Einzelnen Beitrag anzeigen

Popov
(Gast)

n/a Beiträge
 
#17

AW: Stringgrid in INI file schreiben

  Alt 26. Apr 2014, 01:51
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;
  Mit Zitat antworten Zitat