AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Stringgrid in INI file schreiben

Ein Thema von rhodan · begonnen am 25. Apr 2014 · letzter Beitrag vom 26. Apr 2014
Antwort Antwort
Popov
(Gast)

n/a Beiträge
 
#1

AW: Stringgrid in INI file schreiben

  Alt 26. Apr 2014, 00:17
Delphi-Quellcode:
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;
Nicht groß geprüft, sollte aber funktionieren.
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 03:39 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