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:40
Wofür sollte denn eine extra Sektion benötigt werden?
Jep. Ich war gedanklich noch im zweiten Beispiel und da steht jeder Ident für eine Zelle.
  Mit Zitat antworten Zitat
Popov
(Gast)

n/a Beiträge
 
#2

AW: Stringgrid in INI file schreiben

  Alt 26. Apr 2014, 00: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
Benutzerbild von rhodan
rhodan

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

AW: Stringgrid in INI file schreiben

  Alt 26. Apr 2014, 01:19
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;
[DCC Fehler] source.pas(54): E2003 Undeklarierter Bezeichner: 'RowCount' kein plan warum er den nicht erkennt :S
  Mit Zitat antworten Zitat
Popov
(Gast)

n/a Beiträge
 
#4

AW: Stringgrid in INI file schreiben

  Alt 26. Apr 2014, 01:31
RowCount ist eine Eigenschaft von StringGrid. Du hast das With StringGrid1 do vergessen. In meinem Code steht:
Delphi-Quellcode:
begin
...
  with StringGrid1 do
  begin
...
    try
...
      Ini.WriteInteger(IniSelRC, IniRowCount, RowCount);
Mit with kann man sich sparen StringGrid1 immer wieder zu schreiben. Ohne with würde das so aussehen:
Delphi-Quellcode:
begin
...
  //with StringGrid1 do
  begin
...
    try
...
      Ini.WriteInteger(IniSelRC, IniRowCount, StringGrid1.RowCount);
Das gleiche natürlich auch bei ColCount, Cells usw.
  Mit Zitat antworten Zitat
Benutzerbild von rhodan
rhodan

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

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
Popov
(Gast)

n/a Beiträge
 
#6

AW: Stringgrid in INI file schreiben

  Alt 26. Apr 2014, 02:12
Delphi-Quellcode:
//schreiben
...
begin
  IniFile := ChangeFileExt(ParamStr(0), '.ini'); //IniFile ist ein String mit dem IniPfad
  with strgrid do
...
    Ini :=TIniFile.Create(ExtractFilePath(ParamStr(0))+'myinifile.ini'); //hier hast du einen eigenen Pfad
    try
...
end;
Delphi-Quellcode:
//lesen
...
begin
  IniFile := ChangeFileExt(ParamStr(0), '.ini'); //IniFile ist ein String mit dem IniPfad
  with strgrid do
..
  Ini := TIniFile.Create(IniFile); //hier benutzt du den String IniFile für dern Pfad
    try
...
Du gibst verschiedene Pfade an, deshalb schreibt er in eine Ini und liest aus einer anderen.

Das ist auch der Grund wieso man den Ini-Pfad, wenn man es auf verschiedene Prozeduren verteilt, am besten immer in eine Funktion packt. Dann kann man sich nicht verschreiben. Zum Beispiel so:
Delphi-Quellcode:
function IniFile: String
begin
  Result := ChangeFileExt(ParamStr(0), '.ini');
end;
  Mit Zitat antworten Zitat
Benutzerbild von rhodan
rhodan

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

AW: Stringgrid in INI file schreiben

  Alt 26. Apr 2014, 16:19
ahh....das hatte ich übersehen...danke!!
  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 22:51 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