Autor Beitrag
Black200607
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 50

Win XP
Pascal(Free Pascal/Lazarus), Java, Php, Python
BeitragVerfasst: Mi 01.11.06 13:16 
Wie der Titel schon sagt.
Wie speichere ich in eine *.txt Datei und lade die gespeicherten Comboboxen wieder :?: :?:
Bitte helft mir!
Danke im Voraus.

Ps: Noch eine Frage: schreibt man Voraus mit einem oder mit zwei "r"!
jakobwenzel
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1889
Erhaltene Danke: 1

XP home, ubuntu
BDS 2006 Prof
BeitragVerfasst: Mi 01.11.06 13:22 
Was meinst du mit speichern?
Willst du speichern, welcher Eintrag selektiert ist, oder sollen alle Einträge gespeichert werden?

_________________
I thought what I'd do was, I'd pretend I was one of those deaf-mutes.
Marc.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1876
Erhaltene Danke: 129

Win 8.1, Xubuntu 15.10

BeitragVerfasst: Mi 01.11.06 13:31 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
//speichern:
 combobox1.Items.SaveToFile();
//laden:
  combobox1.Items.LoadFromFile();

vo|raus mit einem "r" ;)
Black200607 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 50

Win XP
Pascal(Free Pascal/Lazarus), Java, Php, Python
BeitragVerfasst: Mi 01.11.06 14:51 
Ich möchte alle einträge speichern also den zustand!

DankeMarc.,
dass du mir gesagt hast wie man Voraus schreibt.
Aber wie ich eine speichere is klar, aber ich möchte 40 speichern!
jakobwenzel
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1889
Erhaltene Danke: 1

XP home, ubuntu
BDS 2006 Prof
BeitragVerfasst: Mi 01.11.06 19:52 
Dann guck dir mal StringList, StringList.Delimiter und StringList.DelimitedText an.
Einträge und ItemIndex in ne StringList schreiben, Delimiter setzen, DelimitedText in ne 2. StringList schreiben und die wenn du das mit allen Boxen gemacht hast speichern.

_________________
I thought what I'd do was, I'd pretend I was one of those deaf-mutes.
hansa
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3079
Erhaltene Danke: 9



BeitragVerfasst: Mi 01.11.06 20:28 
user profile iconBlack200607 hat folgendes geschrieben:
dass du mir gesagt hast wie man Voraus schreibt.


Mal wieder sagenhafte Aussage. :mrgreen:

Du mußt doch nur die Eigenschaften in eine Ini schreiben !

Hier ein Beispiel für Forms :

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
procedure TfrmKey.FormClose(Sender: TObject; var Action: TCloseAction);
var FensterIni : TIniFile;
begin
  inherited;
  if not CDStart then begin
    try
      FensterIni := TIniFile.Create(FensterDateiName);
      FensterIni.WriteInteger(Name,'Left',Left);
      FensterIni.WriteInteger(Name,'Top',Top);
      FensterIni.WriteInteger(Name,'Width',Width);
      FensterIni.WriteInteger(Name,'Height',Height);
    finally
      FensterIni.Free;
    end;
  end;
  Action := caFree;
end;


Selbst die Items der Combobox kann man da drin speichern. Der Trick ist der Name. Im Beispiel ist das zwar der Name der Form, aber die ComboBox stellt doch kein Hindernis dar. Auch die hat einen Namen. Vorteil der INI ist eben, daß die das meiste selber macht. Ist zwar auch eine Textdatei, aber Du benutzt ja TIniFile. Hierdurch stehen Dir eben zusätzlich die Methoden wie hier WriteInteger zur Verfügung. Würde das als reiner Text behandelt, dann kann man die Methoden zwar selber schreiben, aber es ist doch schon alles vorhanden. :shock:

_________________
Gruß
Hansa
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Mo 06.11.06 20:22 
FindComponent sollte noch erwähnt werden!
ausblenden Delphi-Quelltext
1:
2:
for X := 1 to 10 do
  TCombobox(FindComponent('Combobox' + IntToStr(X))).*

Würde alle Comboboxen von 1 bis 10 durchgehen, also Combobox1, Combobox2, ... Hat den Vorteil, dass du nicht für jede Combobox die selbe Schleife kopieren musst und am Ende 40 Schleifen im Source hast xD.

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
hansa
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3079
Erhaltene Danke: 9



BeitragVerfasst: Mo 06.11.06 21:25 
GTA, das hast Du jetzt nur halb verstanden. Zumindest meinen Beitrag. :D Weiß nicht, aber falls es möglich ist, meinen Form-Code in einem gemeinsamen Ereignis der Comboboxen unterzubringen, dann ist es wohl besser den Code den ganzen Comboboxen mitzuteilen, als sich diese erst mit FindComponent mühsam zusammenzusuchen und dann einzeln dasselbe zu machen wie gehabt. Über "Name" sind die Comboboxen eindeutig zu identifizieren und der INI ist das sowas von egal, wie die einzelnen Comboboxen jetzt genau heißen. 8)

Es wird dann so eine INI aufgebaut :

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
[frmLrAendern]
Left=76
Top=26
[frmLiefers]
Left=76
Top=26
[frmAuftragsBearb]
Left=230
Top=143
Width=482
Height=511
[frmArtEing]
Left=0
Top=0
Width=1024
Height=738
[frmArtStammVerw]
Left=3
Top=0
Width=318
Height=210


Die Reihenfolge der Einträge spielt keine Rolle. Man sieht aber schön die Reihenfolge der Forms, die nach und nach in der Größe verändert wurden und wie die momentan aussehen sollen. Ihr müßt auch mal etwas Phantasie mitbringen. Stelle Dir mal folgende Situation vor : zweigeteilter PC, morgens artbeitet irgendeiner und mitttags ein anderer. Der eine will Comboboxen, oder was weiß ich links oben haben und der von mittags rechts unten. Na und ? Sollen die doch nur machen. Jeder kriegt eben eigene INI und die kommt dann eben in entsprechende User-Verzeichnisse und das wars. Jeder wird sein Programm so vorfinden, wie er es verlassen hat (zumindest nach Neuanmeldung). Der von mittags will plötzlich was umfärben und das nicht immer jeden Tag neu machen ? -> Eintrag in INI. Jetzt kommt der von morgens und sagt, er hätte sich total verhauen. Mittlerweile sei alles schief. :mrgreen: No problem. Er kriegt wieder die Standardeinstellungen und kann wiieder neu alles rumschieben. Einfach entsprechende INI löschen.

_________________
Gruß
Hansa
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Di 07.11.06 06:49 
Er will aber vermutlich 40 Comboboxen auf EINMAL speichern und dann ist FindComponent doch sinnvoll.

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
hansa
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3079
Erhaltene Danke: 9



BeitragVerfasst: Di 07.11.06 12:14 
Vielleicht braucht er das einmal am Anfang, um die Ini zu erstellen. Aber warum ? Sind die Comboboxen schon am Anfang einigermaßen richtig, dann braucht er die INI ja nicht mal. Dann ist der Zustand der Boxen so, wie er sie auf die Form gelegt hat usw. Baut er den INI-Code z.B. im OnClick oder im OnEnter ein, dann erhielte die jeweilige Combobox einen Eintrag in der INI, z.B. wenn sie zum ersten mal angeklickt wird und fertig.

_________________
Gruß
Hansa
Black200607 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 50

Win XP
Pascal(Free Pascal/Lazarus), Java, Php, Python
BeitragVerfasst: Sa 11.11.06 09:00 
Ich habe noch nicht erwähnt, dass ich ein Anfänger bin.
Ich habe von euren Antworten fast nichts verstanden.
Aber ich bin auf Stringlists gestoßen (Diese Idee hatte schon Jakobwenzel), und das ist doch nicht schlecht.
Könnte man die 40 Comboboxen nicht in einer Stringlist speichern?


Zuletzt bearbeitet von Black200607 am Sa 11.11.06 12:11, insgesamt 1-mal bearbeitet
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Sa 11.11.06 10:26 
Meine Antwort + die von user profile iconMarc.:
ausblenden Delphi-Quelltext
1:
2:
for X := 1 to 40 do  
  TCombobox(FindComponent('Combobox' + IntToStr(X))).Items.SaveToFile('C:\Combobox' + IntToStr(X) + '.txt');

Speichert alle Comboboxen, falls diese Combobox1 - Combobox40 heißen.

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
Black200607 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 50

Win XP
Pascal(Free Pascal/Lazarus), Java, Php, Python
BeitragVerfasst: Sa 11.11.06 12:09 
Das war zwar eine gute Idee Gta, hat auch auch funktioniert, aber ich möchte den Zustand speichern und nicht den Inhalt!
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Sa 11.11.06 14:50 
Das aktuell ausgewählte? Das geht dann wirklich mit einer StringList.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
var
  SList: TStringList;
  X:     Integer;
begin
  SList := TStringList.Create;

  for X := 1 to 40 do    
    SList.Add(TCombobox(FindComponent('Combobox' + IntToStr(X))).Text);

  SList.SaveToFile('C:\Combobox.txt');
  SList.Free;
end;

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
Coder
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1383
Erhaltene Danke: 1

WinXP
D2005 PE
BeitragVerfasst: Sa 11.11.06 15:00 
Ich finde man sollte lieber den ItemIndex speichern und nicht was in der ComboBox steht.
ItemIndex ist die Position des ausgewählten Items.
Das spart Platz da nur eine Zahl gespeichert wird.
Am Ende kommts aber auf das selbe raus.

Zum speichern
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
var
  SList: TStringList;
  i:     Integer;
begin
  SList := TStringList.Create;

  for i := 1 to 40 do    
    SList.Add(IntToStr(TCombobox(FindComponent('Combobox' + IntToStr(i))).ItemIndex));

  SList.SaveToFile('C:\Combobox.txt');
  SList.Free;
end;


Zum Laden
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
var
  SList: TStringList;
  i:     Integer;
begin
  SList := TStringList.Create;
  SList.LoadFromFile('C:\Combobox.txt');

  for i := 1 to 40 do    
    TCombobox(FindComponent('Combobox' + IntToStr(i))).ItemIndex := StrToInt(SList[i]);

  SList.Free;
end;


Ungetestet

MfG
Black200607 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 50

Win XP
Pascal(Free Pascal/Lazarus), Java, Php, Python
BeitragVerfasst: Sa 11.11.06 18:56 
Das Speichern klappt :D
Aber beim Laden kommt eine Fehlermeldung:

:twisted: Listenindex überschreitet das Maximum (40)


Wieso? Es sind genau 40 Comboboxen im Formfenster.
Coder
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1383
Erhaltene Danke: 1

WinXP
D2005 PE
BeitragVerfasst: Sa 11.11.06 18:59 
Sorry
So müsste es gehen.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
var
  SList: TStringList;
  i:     Integer;
begin
  SList := TStringList.Create;
  SList.LoadFromFile('C:\Combobox.txt');

  for i := 1 to 40 do    
    TCombobox(FindComponent('Combobox' + IntToStr(i))).ItemIndex := StrToInt(SList[i-1]);

  SList.Free;
end;


MfG
Black200607 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 50

Win XP
Pascal(Free Pascal/Lazarus), Java, Php, Python
BeitragVerfasst: Sa 11.11.06 19:11 
Dankeschön :!: :!: :!:
Jetzt klappt es endlich.