Einzelnen Beitrag anzeigen

Benutzerbild von rhodan
rhodan

Registriert seit: 4. Okt 2005
Ort: Hamburg
150 Beiträge
 
Delphi 7 Personal
 
#20

AW: Stringgrid in INI file schreiben

  Alt 26. Apr 2014, 01:41
ok habs hinbekommen...schreibmethode:

Delphi-Quellcode:
//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;
ini sieht dann so aus:
Delphi-Quellcode:
[Sel1]
0=,,
1=,rhodan,10
2=,robin,20
3=,,
RowCount=3
ColCount=3
FixRows=1
FixCols=1
lesemethode:
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
  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;
passiert leider gar nichts.... hab grad nen blackout....:S

schreiben funktioniert..aber lesen nicht

Geändert von rhodan (26. Apr 2014 um 01:55 Uhr)
  Mit Zitat antworten Zitat