Einzelnen Beitrag anzeigen

hoika

Registriert seit: 5. Jul 2006
Ort: Magdeburg
8.270 Beiträge
 
Delphi 10.4 Sydney
 
#10

AW: StringGrid aus Form2 in Form1 abspeichern

  Alt 6. Sep 2016, 14:59
Hallo,
ah,

< Unit1 und Unit2 kennen sich! >

Und woher kennt Unit2 SaveStringGrid.
In welcher Unit ist das deklariert?

Mal so in der Schnelle:

Delphi-Quellcode:

unit LoadSaveStringGrid;

interface

uses
  System, Grids; // ???

procedure SaveStringGrid(StringGrid: TStringGrid; const FileName: TFileName);

procedure LoadStringGrid(StringGrid: TStringGrid; const FileName: TFileName);

implementation

procedure SaveStringGrid(StringGrid: TStringGrid; const FileName: TFileName);
var
  f: TextFile;
  i, k: Integer;
begin
  AssignFile(f, FileName);
  Rewrite(f);
  with StringGrid do
  begin
    // Write number of Columns/Rows
    Writeln(f, ColCount);
    Writeln(f, RowCount);
    // loop through cells
    for i := 0 to ColCount - 1 do
      for k := 0 to RowCount - 1 do
        Writeln(F, Cells[i, k]);
  end;
  CloseFile(F);
end;

// Load a TStringGrid from a file

procedure LoadStringGrid(StringGrid: TStringGrid; const FileName: TFileName);
var
  f: TextFile;
  iTmp, i, k: Integer;
  strTemp: String;
begin
  AssignFile(f, FileName);
  Reset(f);
  with StringGrid do
  begin
    // Get number of columns
    Readln(f, iTmp);
    ColCount := iTmp;
    // Get number of rows
    Readln(f, iTmp);
    RowCount := iTmp;
    // loop through cells & fill in values
    for i := 0 to ColCount - 1 do
      for k := 0 to RowCount - 1 do
      begin
        Readln(f, strTemp);
        Cells[i, k] := strTemp;
      end;
  end;
  CloseFile(f);
end;

end.
Heiko

Geändert von hoika ( 6. Sep 2016 um 15:06 Uhr)
  Mit Zitat antworten Zitat