Einzelnen Beitrag anzeigen

Blup

Registriert seit: 7. Aug 2008
Ort: Brandenburg
1.429 Beiträge
 
Delphi 10.4 Sydney
 
#11

AW: Zeilenumbruch aus TStringList löschen

  Alt 5. Sep 2011, 13:37
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;
  Mit Zitat antworten Zitat