Delphi-PRAXiS
Seite 2 von 2     12   

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi Zeilenumbruch aus TStringList löschen (https://www.delphipraxis.net/162777-zeilenumbruch-aus-tstringlist-loeschen.html)

Blup 5. Sep 2011 13:37

AW: Zeilenumbruch aus TStringList löschen
 
Die vorherige Variante hat noch einen kleinen Fehler bei der Zuweisung von RowCount.
Delphi-Quellcode:
procedure FillGridFromStringlist(List: TStrings; Grid: TStringGrid; ColsPerRow: integer);
var
  i, x0, y0, x, y: integer;
begin
  if not Assigned(List) or not Assigned(Grid) then
    raise Exception.Create('Liste und Grid müssen vorhanden sein.');

  y0 := Grid.FixedRows;
  x0 := Grid.FixedCols;

  if (ColsPerRow < 1) or (ColsPerRow > (Grid.ColCount - x0)) then
    raise Exception.CreateFmt('Parameter ungültig: ColsPerRow = %d', [ColsPerRow]);

  if List.Count = 0 then
    Grid.RowCount := y0 + 1 // eine Zeile ist notwendig
  else
  begin
    Grid.RowCount := y0 + ((List.Count - 1) div ColsPerRow) + 1;

    for i := 0 to List.Count - 1 do
    begin
      x := x0 + i div ColsPerRow;
      y := y0 + i mod ColsPerRow;
      Grid.Cells[x, y] := List[i];
    end;
  end;
end;

DeddyH 5. Sep 2011 13:42

AW: Zeilenumbruch aus TStringList löschen
 
Man könnte aber auch ColCount an ColsPerRow anpassen ;)


Alle Zeitangaben in WEZ +1. Es ist jetzt 09:49 Uhr.
Seite 2 von 2     12   

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz