Delphi-PRAXiS
Seite 1 von 2  1 2      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Programmieren allgemein (https://www.delphipraxis.net/40-programmieren-allgemein/)
-   -   Delphi StringGrid aus Form2 in Form1 abspeichern (https://www.delphipraxis.net/190161-stringgrid-aus-form2-form1-abspeichern.html)

strom 6. Sep 2016 10:11

StringGrid aus Form2 in Form1 abspeichern
 
Hallo,

möchte gerne, wenn das Hauptformular(Form1) beendet wird, dass das StringGrid von Form2 abgespeichert wird.

Delphi-Quellcode:
procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
   DeleteFile(ExtractFilePath(ParamStr(0)) + 'Ereignisprotokoll.dat');
  SaveStringGrid(Form2.StringGrid1, ExtractFilePath(ParamStr(0)) + 'Ereignisprotokoll.dat');
end;

mkinzler 6. Sep 2016 10:14

AW: StringGrid aus Form2 in Form1 abspeichern
 
Und? Funktioniert es so nicht? Fehler?

hoika 6. Sep 2016 10:20

AW: StringGrid aus Form2 in Form1 abspeichern
 
Hallo,

ColCount und RowCount setzen und dann

Delphi-Quellcode:
for i := 0 to StringGrid1.RowCount - 1 do
  StringGrid2.Rows[i].Assign(StringGrid1.Rows[i]);

strom 6. Sep 2016 12:03

AW: StringGrid aus Form2 in Form1 abspeichern
 
Zitat:

Fehlermeldung : Undeklarierter Bezeichner "SaveStringGrid"
Unit1 und Unit2 kennen sich!

himitsu 6. Sep 2016 12:09

AW: StringGrid aus Form2 in Form1 abspeichern
 
Was ist SaveStringGrid und wo liegt das?

DeddyH 6. Sep 2016 12:09

AW: StringGrid aus Form2 in Form1 abspeichern
 
Und wo steht SaveStringGrid? Vermutlich lediglich im implementation-Abschnitt einer der Units.

dGeek 6. Sep 2016 12:15

AW: StringGrid aus Form2 in Form1 abspeichern
 
Zitat:

möchte gerne, wenn das Hauptformular(Form1) beendet wird, dass das StringGrid von Form2 abgespeichert wird.
Zitat:

Zitat von hoika (Beitrag 1346923)
Hallo,

ColCount und RowCount setzen und dann

Delphi-Quellcode:
for i := 0 to StringGrid1.RowCount - 1 do
  StringGrid2.Rows[i].Assign(StringGrid1.Rows[i]);

Ich habe nichts von einem zweiten StringGrid gelesen :|

himitsu 6. Sep 2016 12:41

AW: StringGrid aus Form2 in Form1 abspeichern
 
Wenn die MainForm geschlossen wird, dann beendet sich eh alles,
also warum speichert Form2 sich nicht selber? (OnDestroy)

dGeek 6. Sep 2016 13:08

AW: StringGrid aus Form2 in Form1 abspeichern
 
http://www.swissdelphicenter.ch/de/showcode.php?id=941
Zitat:

...ein TStringGrid in eine Datei speichern & laden?
Da hat er auch "SaveStringGrid" her.
Nur ich verstehe nicht wo das Problem ist diese Prozedur zu verwenden.

hoika 6. Sep 2016 14:59

AW: StringGrid aus Form2 in Form1 abspeichern
 
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.


Alle Zeitangaben in WEZ +1. Es ist jetzt 02:52 Uhr.
Seite 1 von 2  1 2      

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