Autor |
Beitrag |
Floker
Hält's aus hier
Beiträge: 7
WIN 2000
D2005 Pers
|
Verfasst: So 26.06.05 16:24
Hi
Also Folgendes: Ich habe ein StringGrid mit einer variablen anzahl Zeichen (die passende Variable dafür heißt bei mir "JobCount") und drei spalten.
Ich will die einträge in inidateien speicher, und wieder laden. im moment läuft das so:
Delphi-Quelltext 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18:
| procedure TMainForm.FormClose(Sender: TObject; var Action: TCloseAction); begin try Config := TIniFile.Create('InstantBackup.ini'); Config.WriteInteger('Jobinfo', 'JobCount', JobCount); JobGrid.Row := JobCount; if JobCount = 0 then JobGrid.Row := 1; repeat begin Config.WriteString(IntToStr(JobGrid.Row), 'Name', JobGrid.Cells[0,JobGrid.Row]); Config.WriteString(IntToStr(JobGrid.Row), 'Directory', JobGrid.Cells[1,JobGrid.Row]); Config.WriteString(IntToStr(JobGrid.Row), 'Mirror', JobGrid.Cells[2,JobGrid.Row]); JobGrid.Row := JobGrid.Row - 1; end; until JobGrid.Row = 1; Config.Destroy; except end; end; |
Delphi-Quelltext 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23:
| procedure TMainForm.FormCreate(Sender: TObject); begin try Config := TIniFile.Create('InstantBackup.ini'); BackupTimer.Interval := Config.ReadInteger('Backup', 'Interval', 60); JobCount := Config.ReadInteger('Jobinfo', 'JobCount', 0); JobGrid.Row := JobCount; if JobCount = 0 then JobGrid.Row := 1; repeat begin JobGrid.Cells[0,JobGrid.Row] := Config.ReadString(IntToStr(JobGrid.Row), 'Name', ''); JobGrid.Cells[1,JobGrid.Row] := Config.ReadString(IntToStr(JobGrid.Row), 'Directory', ''); JobGrid.Cells[2,JobGrid.Row] := Config.ReadString(IntToStr(JobGrid.Row), 'Mirror', ''); JobGrid.Row := JobGrid.Row - 1; end; until JobGrid.Row = 1; Config.Destroy; except end; JobGrid.Cells[0, 0] := 'Name'; JobGrid.Cells[1, 0] := 'Ordner'; JobGrid.Cells[2, 0] := 'Mirror'; StatusBar.Panels[0].Text := 'Zu erledigende Jobs: ' + IntToStr(JobCount); end; |
Leider werden die zeilen nicht geladen!
Nur der jobcount, was dafür sorgt, dass ich leere zeilen habe, wenn ich einen neuen eintrag mache. (drüber)
wo ist da mein fehler? ich hab schon die halbe nacht damit zugebracht!
PS: ich weiß dass es mit nem array besser gehen würde, aber dazu müsste ich eine menge code umschreiben, und ich hab wenig zeit
danke schonmal
Moderiert von Christian S.: Code- durch Delphi-Tags ersetzt.
|
|
Narses
      

Beiträge: 10183
Erhaltene Danke: 1256
W10ent
TP3 .. D7pro .. D10.2CE
|
Verfasst: Mo 27.06.05 01:44
Moin!
Probier das mal so:
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:
| procedure TForm1.FormCreate(Sender: TObject); var Config: TIniFile; i: Integer; begin Config := TIniFile.Create(ChangeFileExt(Application.Exename,'.ini')); BackupTimer.Interval := Config.ReadInteger('Global', 'BackupInterval', 60); JobGrid.Cells[0,0] := 'Nr.'; JobGrid.Cells[1,0] := 'Name'; JobGrid.Cells[2,0] := 'Ordner'; JobGrid.Cells[3,0] := 'Mirror'; JobCount := Config.ReadInteger('Jobinfo', 'JobCount', 0); JobGrid.RowCount := JobCount +2; for i := 1 to JobGrid.RowCount do begin JobGrid.Cells[0,i] := IntToStr(i); JobGrid.Cells[1,i] := Config.ReadString('Jobinfo', 'Name'+IntToStr(i), ''); JobGrid.Cells[2,i] := Config.ReadString('Jobinfo', 'Directory'+IntToStr(i), ''); JobGrid.Cells[3,i] := Config.ReadString('Jobinfo', 'Mirror'+IntToStr(i), ''); end; Config.Free; StatusBar.Panels[0].Text := 'Zu erledigende Jobs: ' + IntToStr(JobCount); end;
procedure TForm1.FormDestroy(Sender: TObject); var Config: TIniFile; i: Integer; begin Config := TIniFile.Create(ChangeFileExt(Application.Exename,'.ini')); Config.EraseSection('Jobinfo'); if (JobGrid.RowCount > 1) then begin Config.WriteInteger('Jobinfo', 'JobCount', JobCount); for i := 1 to JobGrid.RowCount do begin Config.WriteString('Jobinfo', 'Name'+IntToStr(i), JobGrid.Cells[1,i]); Config.WriteString('Jobinfo', 'Directory'+IntToStr(i), JobGrid.Cells[2,i]); Config.WriteString('Jobinfo', 'Mirror'+IntToStr(i), JobGrid.Cells[3,i]); end; end; Config.Free; end; |
Floker hat folgendes geschrieben: | wo ist da mein fehler? |
- Dateiname der INI besser absolut anlegen
- Du verwendest JobGrid.Row wie einen Datensatzzeiger in einer Datenbank, das ist aber nur die Cursorposition; du kannst direkt auf die Zellen zugreifen (über den Index)
- Config.Destroy ist falsch: Config.Free nehmen
- Dein INI-Format ist "ungeschickt" gewählt; wenn man die Jobdaten in eine eigene Section packt, kann man diese per .EraseSection() komplett löschen, damit keine "Leichen" entstehen, wenn man Zeilen löscht
cu
Narses
|
|
Floker 
Hält's aus hier
Beiträge: 7
WIN 2000
D2005 Pers
|
Verfasst: Mo 27.06.05 13:43
Hi
Mit deiner lösung geht es bestimmt, aber ich müsste eine ganze menge code umschreiben um die nummer in die erste spalte zu bekommen..
ich hab etwas gefunden, was vielleicht einfacher ist:
www.swissdelphicente.../showcode.php?id=941
dank dir für den tipp mit dem dateinamen, ist echt besser.
bis dann
|
|
Narses
      

Beiträge: 10183
Erhaltene Danke: 1256
W10ent
TP3 .. D7pro .. D10.2CE
|
Verfasst: Di 28.06.05 10:49
Moin!
Floker hat folgendes geschrieben: | Mit deiner lösung geht es bestimmt, aber ich müsste eine ganze menge code umschreiben um die nummer in die erste spalte zu bekommen.. |
Dann lass die Nummer doch einfach weg!  Mein Code ist ja nur als Demo zu verstehen, wie man das machen könnte, mach´s, wie du willst.
Floker hat folgendes geschrieben: | ich hab etwas gefunden, was vielleicht einfacher ist: |
Den angegebenen Code empfehle ich persönlich nicht.
cu
Narses
|
|
|