Autor Beitrag
chefkoch
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 48

WIN XP pro
D7
BeitragVerfasst: So 22.12.02 15:38 
Tach zusammen!

Ich schreibe gerade an einem Rechnungsverwaltungsprogramm. Habe angefangen, die Kundenverwaltung dazu zu programmieren. Leider arbeite ich das erste mal mit StringGrid und weiss daher nicht, wie ich die Inhalte speichern und laden kann. Wäre cool, wenn mir jmd. helfen könnte.

Dateivereinbarung:
ausblenden volle Höhe Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
 tkundendaten_speichertyp_einzeln = RECORD
          anrede                      : string[255];
          name                        : string[255];
          zusatz                      : string[255];
          strasse                     : string[255];
          plz                         : string[255];
          ort                         : string[255];
     end;

     tkundendaten_speichern = array[0..999] of tkundendaten_speichertyp_einzeln;

var
  main: Tmain;
  main_kundenspeicher       : tkundendaten_speichern;
  main_kundenspeicher_datei : file of tkundendaten_speichern;


const
  main_kundenspeicher_dateiname = 'daten/kunden.rkd';

.
.
.


Prozeduren zum speichern / laden


    procedure main_kundendaten_speichern;
    var i,x : integer;
    begin
         for i := 0 to main.main_kundendaten_grid.rowcount-1 do
         begin
              if main_kundenspeicher[i].anrede <> '' then
                   main_kundenspeicher[i].anrede := main.main_kundendaten_grid.cells[0,i];
         end;
         assignfile(main_kundenspeicher_datei,main_kundenspeicher_dateiname);
         reset(main_kundenspeicher_datei);
         write(main_kundenspeicher_datei,main_kundenspeicher);
         close(main_kundenspeicher_datei);
         showmessage('                      gespeichert               ');
    end;

    procedure main_kundendaten_oeffnen;
    var i : integer;
    begin
            if fileexists(main_kundenspeicher_dateiname) then
            begin
                 reset(main_kundenspeicher_datei)
            end
            else
            begin
                 rewrite(main_kundenspeicher_datei);
            end;

              assign(main_kundenspeicher_datei,main_kundenspeicher_dateiname);
              reset(main_kundenspeicher_datei);
              read(main_kundenspeicher_datei,main_kundenspeicher);
              close(main_kundenspeicher_datei);
              main.main_kundendaten_grid.Cells[0,i] := main_kundenspeicher[i].anrede;
    end;

In diesem Beispiel soll er nur die Andrede aus allen Spalten speichern. Wäre allerdings cool, wenn das schneller und einfacher gehen würde.

Danke im Vorraus und Gruß aus Düsseldorf

Christian

(23.12. 10:42 Tino) Code-Tags hinzugefügt
Cyrus
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 56



BeitragVerfasst: Mo 23.12.02 11:28 
Hi vielleicht hilft das:

ausblenden volle Höhe Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
// Save a TStringGrid to a file 

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; 


// Save StringGrid1 to 'c:\temp.txt': 

procedure TForm1.Button1Click(Sender: TObject); 
begin 
  SaveStringGrid(StringGrid1, 'c:\temp.txt'); 
end; 

// Load StringGrid1 from 'c:\temp.txt': 

procedure TForm1.Button2Click(Sender: TObject); 
begin 
  LoadStringGrid(StringGrid1, 'c:\temp.txt'); 
end;


Greez Cyrus

_________________
Wer glaub er ist, hört auf zu werden!
Delphi Rulez!!!
chefkoch Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 48

WIN XP pro
D7
BeitragVerfasst: Mo 23.12.02 11:31 
Danke Cyrus!

Hat gefunzt.

Bin jetzt endlich ein ganzes Stück weiter mit dem Drecksproggi!

C ya

Christian
Cyrus
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 56



BeitragVerfasst: Mo 23.12.02 11:35 
Keine Ursache NP!!!

_________________
Wer glaub er ist, hört auf zu werden!
Delphi Rulez!!!