![]() |
AW: Stringgrid in INI file schreiben
Warum speicherst du in der Ini nicht (mehr) die Informationen von Zeilen- und Spaltenanzahl?
Das würde doch ungemein helfen, oder? Und das
Delphi-Quellcode:
kannst du direkt vor die
ini.EraseSection
Delphi-Quellcode:
-Schleife setzen.
for
Ach ja, 4 Spalten von 0 an gezählt gehen von 0 bis 3 ;) |
AW: Stringgrid in INI file schreiben
Delphi-Quellcode:
Nicht groß geprüft, sollte aber funktionieren.
const
IniSelRC = 'Sel3'; var x, y, k: Integer; IniFile, s, xs, ys: String; sl: TStringList; Ini: TIniFile; begin IniFile := ChangeFileExt(ParamStr(0), '.ini'); with StringGrid1 do begin Ini := TIniFile.Create(IniFile); try //Löscht den alten Inhalt Ini.EraseSection(IniSelRC); k := 0; for x := 0 to ColCount - 1 do for y := 0 to RowCount - 1 do begin Inc(k); Ini.WriteString(IniSelRC, IntToStr(k), Format('%d:%d:%s', [x, y, Cells[x, y]])); end; finally Ini.Free; end; for x := 0 to ColCount do for y := 0 to RowCount do Cells[x, y] := ''; ColCount := 0; RowCount := 0; Ini := TIniFile.Create(IniFile); try sl := TStringList.Create; try Ini.ReadSection(IniSelRC, sl); for k := 0 to sl.Count - 1 do begin s := Ini.ReadString(IniSelRC, sl[k], ''); xs := System.Copy(s, 1, Pos(':', s) - 1); System.Delete(s, 1, Pos(':', s)); ys := System.Copy(s, 1, Pos(':', s) - 1); System.Delete(s, 1, Pos(':', s)); //Fügt Splaten und Zeilen bei Bedarf if ColCount < (StrToInt(xs) + 1) then ColCount := StrToInt(xs) + 1; if RowCount < (StrToInt(ys) + 1) then RowCount := StrToInt(ys) + 1; //Fügt Fixed-Stalten und -Zeilen bei Bedarf if (ColCount> 1) and (FixedCols = 0) then FixedCols := 1; if (RowCount > 1) and (FixedRows = 0) then FixedRows := 1; Cells[StrToInt(xs), StrToInt(ys)] := s; end; finally sl.Free; end; {} finally Ini.Free; end; end; end; |
AW: Stringgrid in INI file schreiben
ok..mit dieser änderung hab ichs hinbekommen das keine unnötigen leeren zeilen abgespeichert werden:
Delphi-Quellcode:
hilf mir bitte wie ich beim einlesen die nötigen columns erzeuge..ich kriegs nicht hin :F
begin
ini := TIniFile.Create(ExtractFilePath(ParamStr(0))+'myinifile.ini'); try for x := 2 to ColCount do Ini.WriteString('Sel', IntToStr(x-1), Cols[x-1].CommaText); finally Ini.Free; end; |
AW: Stringgrid in INI file schreiben
Achso, du hast das erste Beispiel genommen.
Ich würde da nicht groß fackeln und eine Extra-Sektion erstellen in der du die Anzahl Cols und Rows speicherst. |
AW: Stringgrid in INI file schreiben
Zitat:
Code:
[Sel]
ColCount=4 RowCount=4 FixedColCount=1 FixedRowCount=1 0=... 1=... 2=... 3=... |
AW: Stringgrid in INI file schreiben
Zitat:
|
AW: Stringgrid in INI file schreiben
Der erste Code könnte so aussehen:
Delphi-Quellcode:
const
IniSelRC = 'Sel1'; IniRowCount = 'RowCount'; IniColCount = 'ColCount'; IniFixedRows = 'FixRows'; IniFixedCols = 'FixCols'; var x, y: Integer; IniFile: String; Ini: TIniFile; begin IniFile := ChangeFileExt(ParamStr(0), '.ini'); with StringGrid1 do begin //Speichern Ini := TIniFile.Create(IniFile); try //Löscht den alten Inhalt Ini.EraseSection(IniSelRC); for x := 0 to ColCount do Ini.WriteString(IniSelRC, IntToStr(x), Cols[x].CommaText); Ini.WriteInteger(IniSelRC, IniRowCount, RowCount); Ini.WriteInteger(IniSelRC, IniColCount, ColCount); Ini.WriteInteger(IniSelRC, IniFixedRows, FixedRows); Ini.WriteInteger(IniSelRC, IniFixedCols, FixedCols); finally Ini.Free; end; //Löschen for x := 0 to ColCount do for y := 0 to RowCount do Cells[x, y] := ''; ColCount := 0; RowCount := 0; //Lesen Ini := TIniFile.Create(IniFile); try RowCount := Ini.ReadInteger(IniSelRC, IniRowCount, RowCount); ColCount := Ini.ReadInteger(IniSelRC, IniColCount, ColCount); FixedRows := Ini.ReadInteger(IniSelRC, IniFixedRows, FixedRows); FixedCols := Ini.ReadInteger(IniSelRC, IniFixedCols, FixedCols); for x := 0 to ColCount do Cols[x].CommaText := Ini.ReadString(IniSelRC, IntToStr(x), ''); finally Ini.Free; end; end; end; |
AW: Stringgrid in INI file schreiben
hab jetzt auf verschiedene weisen rumprobiert aber ich kriege immer ne fehlermeldung...beim lesen aus der ini:
Delphi-Quellcode:
procedure TForm2.btnreadClick(Sender: TObject);
const IniSelRC = 'Sel1'; IniRowCount = 'RowCount'; IniColCount = 'ColCount'; IniFixedRows = 'FixRows'; IniFixedCols = 'FixCols'; var x, y: Integer; IniFile: String; Ini: TIniFile; begin Ini := TIniFile.Create(IniFile); try RowCount := Ini.ReadInteger(IniSelRC, IniRowCount, RowCount); ColCount := Ini.ReadInteger(IniSelRC, IniColCount, ColCount); FixedRows := Ini.ReadInteger(IniSelRC, IniFixedRows, FixedRows); FixedCols := Ini.ReadInteger(IniSelRC, IniFixedCols, FixedCols); for x := 0 to ColCount do Cols[x].CommaText := Ini.ReadString(IniSelRC, IntToStr(x), ''); finally Ini.Free; end; end; end;
Delphi-Quellcode:
kein plan warum er den nicht erkennt :S
[DCC Fehler] source.pas(54): E2003 Undeklarierter Bezeichner: 'RowCount'
|
AW: Stringgrid in INI file schreiben
RowCount ist eine Eigenschaft von StringGrid. Du hast das
Delphi-Quellcode:
vergessen. In meinem Code steht:
With StringGrid1 do
Delphi-Quellcode:
Mit with kann man sich sparen StringGrid1 immer wieder zu schreiben. Ohne with würde das so aussehen:
begin
... with StringGrid1 do begin ... try ... Ini.WriteInteger(IniSelRC, IniRowCount, RowCount);
Delphi-Quellcode:
Das gleiche natürlich auch bei ColCount, Cells usw.
begin
... //with StringGrid1 do begin ... try ... Ini.WriteInteger(IniSelRC, IniRowCount, StringGrid1.RowCount); |
AW: Stringgrid in INI file schreiben
ok habs hinbekommen...schreibmethode:
Delphi-Quellcode:
ini sieht dann so aus:
//schreiben
procedure TForm2.btnwriteClick(Sender: TObject); const IniSelRC = 'Sel1'; IniRowCount = 'RowCount'; IniColCount = 'ColCount'; IniFixedRows = 'FixRows'; IniFixedCols = 'FixCols'; var x, y: Integer; IniFile: String; Ini: TIniFile; begin IniFile := ChangeFileExt(ParamStr(0), '.ini'); with strgrid do begin //Speichern Ini :=TIniFile.Create(ExtractFilePath(ParamStr(0))+'myinifile.ini'); try //Löscht den alten Inhalt Ini.EraseSection(IniSelRC); for x := 0 to ColCount do Ini.WriteString(IniSelRC, IntToStr(x), Cols[x].CommaText); Ini.WriteInteger(IniSelRC, IniRowCount, RowCount); Ini.WriteInteger(IniSelRC, IniColCount, ColCount); Ini.WriteInteger(IniSelRC, IniFixedRows, FixedRows); Ini.WriteInteger(IniSelRC, IniFixedCols, FixedCols); finally Ini.Free; end; end; end;
Delphi-Quellcode:
lesemethode:
[Sel1]
0=,, 1=,rhodan,10 2=,robin,20 3=,, RowCount=3 ColCount=3 FixRows=1 FixCols=1
Delphi-Quellcode:
passiert leider gar nichts.... hab grad nen blackout....:S
procedure TForm2.btnreadClick(Sender: TObject);
const IniSelRC = 'Sel1'; IniRowCount = 'RowCount'; IniColCount = 'ColCount'; IniFixedRows = 'FixRows'; IniFixedCols = 'FixCols'; var x, y: Integer; IniFile: String; Ini: TIniFile; begin IniFile := ChangeFileExt(ParamStr(0), '.ini'); with strgrid do begin Ini := TIniFile.Create(IniFile); try RowCount := Ini.ReadInteger(IniSelRC, IniRowCount, RowCount); ColCount := Ini.ReadInteger(IniSelRC, IniColCount, ColCount); FixedRows := Ini.ReadInteger(IniSelRC, IniFixedRows, FixedRows); FixedCols := Ini.ReadInteger(IniSelRC, IniFixedCols, FixedCols); for x := 0 to ColCount do Cols[x].CommaText := Ini.ReadString(IniSelRC, IntToStr(x), ''); finally Ini.Free; end; end; end; schreiben funktioniert..aber lesen nicht |
Alle Zeitangaben in WEZ +1. Es ist jetzt 09:37 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz