Autor Beitrag
Mike19
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 256

Win XP, Vista, Win 7
Delphi 2005, Turbo Delphi
BeitragVerfasst: Mi 27.04.05 18:40 
Hallo,

ich hab wieder mal eine Frage.

Ich habe eine ComboBox, deren Items durch den Benutzer geändert werden können. Dabei können neue Eingaben hinzukommen oder vorhandene gelöscht werden.

Nun möchte ich bei Beendigung des Programms die aktuellen Items in einer Sektion der INI Datei Speichern und beim nächsten Aufruf wieder laden.

Kann mit einer sagen ob und wie das geht ?

Mike
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Mi 27.04.05 18:44 
Suche in: Delphi-Forum, Delphi-Library TINIFILE

In dieser Speicherst Du (in einer gemeinsamen Sektion) folgende Werte:

- 'Count' (Anzahl der Einträge)
- 'Items'+IntToStr(x) (Textzeile aus SL.Items[x], wobei x die Zeilennummer ist)

X geht von 0 bis SL.Count-1

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
Tobias1
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 454

Win 98, XP Prof
D3 Prof, D2005 Prof
BeitragVerfasst: Mi 27.04.05 18:45 
Probiers mal mit
ausblenden Delphi-Quelltext
1:
combobox1.Items.CommaText;					

_________________
Auch das schlechteste Buch hat seine gute Seite: die letzte. (John Osborne)
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Mi 27.04.05 18:46 
Vorwarnung: TStrings.CommaText hat Probleme mit führenden und angehängten Leerzeilen ;-)

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
teamrocket0
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 177
Erhaltene Danke: 1

Win ME, Win XP, Win 7, Win 10
Delphi 7, 10.2 Tokyo
BeitragVerfasst: Di 12.09.06 09:35 
@ BenBe: Das klingt nicht schlecht, aber kannst du mir auch sagen wie ich das in dem folgendem Format einbinden kann?

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
var ini: TIniFile;
    check1: boolean;
    check2: Boolean;
    check3: Boolean;
    check4: Boolean;
    check5: Boolean;
    check6: Boolean;
begin
check1:=checkbox1.Checked;
check2:=checkbox2.Checked;
check3:=checkbox3.Checked;
check4:=checkbox4.Checked;
check5:=checkbox5.Checked;
check6:=checkbox6.Checked;
//ini-Datei schreiben
  ini:=TIniFile.create(ExtractFilePath(ParamStr(0))+ 'einstellungen.ini');
  ini.WriteBool('Checkboxen','Checkbox1',check1);
  ini.WriteBool('Checkboxen','Checkbox2',check2);
  ini.WriteBool('Checkboxen','Checkbox3',check3);
  ini.WriteBool('Checkboxen','Checkbox4',check4);
  ini.WriteBool('Checkboxen','Checkbox5',check5);
  ini.WriteBool('Checkboxen','Checkbox6',check6);
  //Hier soll der gesamt Inhalt der Combobox zur INI-Datei hinzugefügt werden.
//ini schreiben beendet
SaveStringGridToFile(StringGrid1, 'Dateiname.txt');
end;
rd3
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Di 12.09.06 10:01 
Hi,

das geht auch ganz einfach mit den JEDI-Komponenten... Da kannst Du so ziemlich alle Properties der Komponenten mit speichern. Du fügst die Properties über Doppelklick auf die Komponente TFormStorage hinzu.
Hier gibts das Package: homepages.borland.com/jedi/jvcl/

In diesem Fall die Combobox auswählen und dann die dazugehöreige Eigenschaft/Property "Items" hinzufügen... Evtl. brauchst Du nur einen Handler schreiben, der doppelte Einträge herausfischt...

Gruß

rd3
ZeitGeist87
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1593
Erhaltene Danke: 20

Win95-Win10
Delphi 10 Seattle, Rad Studio 2007, Delphi 7 Prof., C++, WSH, Turbo Pascal, PHP, Delphi X2
BeitragVerfasst: Di 12.09.06 10:11 
Ich hab folgende Lösung für dich..
schnell geschrieben..und getestet..dürfte funktionieren =)

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
//Mit dieser Funktion kannst du alle Einträge einer Combobox in die INI schreiben
//Beispielaufruf:
//writeCombobox2INI(Combobox1, '|', 'C:\TestINI.INI', 'Sektion1', 'CItems');
procedure writeCombo2INI(myCombo: TCombobox; Trenner, INIpfad, Sektion, Ident: String);
var i: integer;
    zeile: string;
    myINI: TINIFile;
begin;
 zeile:= '';
 for i:= 1 to myCombo.Items.Count do
  if zeile = '' then
   zeile:= MyCombo.items.strings[i-1]
  else
   zeile:= zeile + trenner + myCombo.items.strings[i-1];

 //damit auch der letzte Eintrag beim Lesen mit ausgegeben wird
 Zeile:= zeile + trenner;

 myINI:= TINIFile.Create(INIpfad);
 myINI.WriteString(sektion, ident, zeile);
 myINI.UpdateFile;
 myINI.Free;
end;

//Und diese Prozedur um die Daten wieder in eine Combobox einzulesen
//Beispielaufruf:
//readComboFromINI('C:\testINI.INI', '|', 'Sektion1', 'CItems', Combobox2);
procedure readComboFromINI(INIpfad, trenner, Sektion, Ident: string; inCombo: TCombobox);
var i: integer;
    zeile: string;
    myINI: TINIFile;
    tempstr: string;
begin;
 zeile:= '';
 tempstr:= '';
 myINI:= TINIFile.Create(INIpfad);
 zeile:= myINI.ReadString(sektion, ident, '');
 myINI.Free;

 for i:= 1 to length(zeile) do
 begin
  if zeile[i] <> trenner then
   tempstr:= tempstr + zeile[i]
  else
  begin
   inCombo.Items.Add(tempstr);
   tempstr:= '';
  end;
 end;
end;


Hoffe ich konnte helfen

LG
Stefan

_________________
Wer Provokationen, Ironie, Sarkasmus oder Zynismus herauslesen kann soll sie ignorieren um den Inhalt meiner Beiträge ungetrübt erfassen zu können.
teamrocket0
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 177
Erhaltene Danke: 1

Win ME, Win XP, Win 7, Win 10
Delphi 7, 10.2 Tokyo
BeitragVerfasst: Di 12.09.06 10:29 
Zitat:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
//Mit dieser Funktion kannst du alle Einträge einer Combobox in die INI schreiben   
//Beispielaufruf:   
//writeCombobox2INI(Combobox1, '|', 'C:\TestINI.INI', 'Sektion1', 'CItems');   
procedure writeCombo2INI(myCombo: TCombobox; Trenner, INIpfad, Sektion, Ident: String);   
var i: integer;   
    zeile: string;   
    myINI: TINIFile;   
begin;   
 zeile:= '';   
 for i:= 1 to myCombo.Items.Count do   
  if zeile = '' then   
   zeile:= MyCombo.items.strings[i-1]   
  else   
   zeile:= zeile + trenner + myCombo.items.strings[i-1];   

 //damit auch der letzte Eintrag beim Lesen mit ausgegeben wird   
 Zeile:= zeile + trenner;   

 myINI:= TINIFile.Create(INIpfad);   
 myINI.WriteString(sektion, ident, zeile);   
 myINI.UpdateFile;   
 myINI.Free;   
end;



Nur ein kleiner Fehler(Zeile 3: writeCombobox2INI muss writeCombo2INI heißen, oder anders herum), aber ansonsten herforragend.

recht herzlichen Dank an ZeitGeist87 :zustimm:
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Di 12.09.06 11:03 
Hallo,

hm..., hätte da noch eine kürzere Variante:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
// speichern
var ini : TIniFile;
    i,z : Integer;
begin
  ini := TIniFile.Create(ExtractFilePath(ParamStr(0))+'meine.ini');
  i := ComboBox.Items.Count;
  ini.WriteInteger('ComboBox','Items',i);//Anzahl Items speichern
  for z := 0 to i - 1 do
    ini.WriteString('ComboBox','Item'+IntToStr(z),ComboBox.Items[z]);
  ini.Free;

// laden
var ini : TIniFile;
    i,z : Integer;
begin
  ini := TIniFile.Create(ExtractFilePath(ParamStr(0))+'meine.ini');
  i := ini.ReadInteger('ComboBox','Items',0);//Anzahl Items ermitteln
  for z := 0 to i - 1 do
    ComboBox.Items.Add(ini.ReadString('ComboBox','Item'+IntToStr(z),''));
  ini.Free;

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )