Autor |
Beitrag |
Cool-Fux
      
Beiträge: 22
|
Verfasst: Do 29.03.07 23:16
Hallo,
ich bin blutiger Anfänger!
Ich möchte ein kleines Programm zum erstellen von Listen schreiben.
Die Auswahl soll über Combobox1 und Combobox2 erfolgen.
Es soll in etwa so funktionieren.
In der Combobox1 habe ich die Werte 1,2,3 und 4 eingetragen, wenn man jetzt den Wert 2
auswählt soll aus der Datei 2.txt bestimmte Werte in der Combobox2 eingetragen werden und dort zur weiteren Auswahl stehen. Mit einen OK Button sollen die Werte aus der Combobox1 und 2 und die da zu gehörigen Werte der Textdatei in einer Liste angezeigt im Programmfenster angezeigt werden und später gespeichert werden.
Wie sieht der Code für die Comboboxen in etwa aus und welche Liste ist hierfür am besten.
(ListView, StringGrid usw.)
Gruß Cool Fux
|
|
Narses
      

Beiträge: 10183
Erhaltene Danke: 1256
W10ent
TP3 .. D7pro .. D10.2CE
|
Verfasst: Do 29.03.07 23:21
Moin und  im Forum!
Deine Fragen laufen darauf hinaus, dass wir dir ein Programm schreiben sollen...  das wird hier nicht so gern gesehen.
Besser wäre es, wenn du uns deine bisherigen Quelltextergebnisse/versuche zeigst und konkrete Fragen stellst, was oder wo etwas nicht funktioniert; dann helfen wir dir sicher gerne weiter.
Für einen ersten Ansatz, so lädt man eine Textdatei in eine ComboBox:
Delphi-Quelltext 1:
| ComboBox1.Items.LoadFromFile('C:\Test.txt'); |
cu
Narses
_________________ There are 10 types of people - those who understand binary and those who don´t.
|
|
Jacer
      
Beiträge: 105
Windows 7, Vista, Ubuntu
HTML,CSS,PHP,Delphi 7
|
Verfasst: Fr 30.03.07 12:05
Als Anfänger rate ich dir, erstmal eine Art Konzept zu erstellen was du genau für ein Programm machen möchtest.
Überlege dir erstmal was für Komponenten du benötigst und wie du sie einsetzen möchtest.
Was muss zB genau bei dem OnClick eines bestimmten Buttons passieren usw.
Dann kanst du dir überlegen mit welcher Realisierung von welcher Komponenten du Probleme hast und kannst konkrete Fragen stellen. So kannst du dir nach und nach alles an Informationen zusammentragen die du brauchst.
"Schick mir mal den Quelltext" ist eine absolute Hass-Frage in diesem (auch in anderen) Forum
Mit ComboBox1.AddItem zum Beispiel fügst du der CmbBox Elemente hinzu.
Der Befehl ItemIndex der Box liefert dir den aktuell ausgewählten Eintrag.
_________________ A look in the eyes often says more than a hundred words could ever express.
|
|
Cool-Fux 
      
Beiträge: 22
|
Verfasst: Mo 02.04.07 20:33
Hallo,
erst einmal vielen Dank für die Antworten.
Ich möchte hier keinen kompletten Code bekommen, sondern Anregungen.
Ich habe jetzt eine Procedure für eine ComboBox geschrieben und komme nicht so richtig weiter.
Hier der Code:
Delphi-Quelltext 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20:
| procedure TForm1.ComboBox1Change(Sender: TObject); var tempStringList : TStrings; i : Integer; begin if ComboBox1.Text = ('HEB') then tempStringList := TStringList.Create; tempStringList.LoadFromFile('tab\heb.txt'); tempStringList.Delete(0); tempStringList.Delete(0); for i := 0 to tempStringList.Count -1 do combobox2.Items.Add(copy(tempStringList[i],1,pos(' ',tempStringList[i]))); tempStringList.Free; if ComboBox1.Text = ('HEA') then tempStringList := TStringList.Create; tempStringList.LoadFromFile('tab\hea.txt'); tempStringList.Delete(0); tempStringList.Delete(0); for i := 0 to tempStringList.Count -1 do combobox2.Items.Add(copy(tempStringList[i],1,pos(' ',tempStringList[i]))); tempStringList.Free; end; |
Hab Ihr eine Idee für Mich?
Gruß
Moderiert von Christian S.: Delphi-Tags hinzugefügt
|
|
Narses
      

Beiträge: 10183
Erhaltene Danke: 1256
W10ent
TP3 .. D7pro .. D10.2CE
|
Verfasst: Mo 02.04.07 23:15
Moin!
Was ist denn nun mit deinem Code, funktioniert daran irgendwas nicht, wo ist das Problem?
cu
Narses
_________________ There are 10 types of people - those who understand binary and those who don´t.
|
|
Cool-Fux 
      
Beiträge: 22
|
Verfasst: Di 03.04.07 19:39
Hallo,
diese Procedure funst:
Delphi-Quelltext 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13:
| procedure TForm1.ComboBox1Change(Sender: TObject); var tempStringList : TStrings; i : Integer; begin if ComboBox1.Text = ('HEB') then tempStringList := TStringList.Create; tempStringList.LoadFromFile('tab\heb.txt'); tempStringList.Delete(0); tempStringList.Delete(0); for i := 0 to tempStringList.Count -1 do combobox2.Items.Add(copy(tempStringList[i],1,pos(' ',tempStringList[i]))); tempStringList.Free; end; |
Und bei dieser erhalte ich eine Fehlermeldung:
Delphi-Quelltext 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20:
| procedure TForm1.ComboBox1Change(Sender: TObject); var tempStringList : TStrings; i : Integer; begin if ComboBox1.Text = ('HEB') then tempStringList := TStringList.Create; tempStringList.LoadFromFile('tab\heb.txt'); tempStringList.Delete(0); tempStringList.Delete(0); for i := 0 to tempStringList.Count -1 do combobox2.Items.Add(copy(tempStringList[i],1,pos(' ',tempStringList[i]))); tempStringList.Free; if ComboBox1.Text = ('HEA') then tempStringList := TStringList.Create; tempStringList.LoadFromFile('tab\hea.txt'); tempStringList.Delete(0); tempStringList.Delete(0); for i := 0 to tempStringList.Count -1 do combobox2.Items.Add(copy(tempStringList[i],1,pos(' ',tempStringList[i]))); tempStringList.Free; end; |
Gruß
Moderiert von Christian S.: Delphi-Tags hinzugefügt
|
|
Narses
      

Beiträge: 10183
Erhaltene Danke: 1256
W10ent
TP3 .. D7pro .. D10.2CE
|
Verfasst: Di 03.04.07 21:00
Moin!
Cool-Fux hat folgendes geschrieben: | Und bei dieser erhalte ich eine Fehlermeldung: |
Und... welche Fehlermeldung... könnte das wohl sein... und vor allem... wo?
cu
Narses
_________________ There are 10 types of people - those who understand binary and those who don´t.
|
|
Cool-Fux 
      
Beiträge: 22
|
Verfasst: Fr 06.04.07 18:59
Hallo,
wir mal die Fehlermeldung als Anlage:
Einloggen, um Attachments anzusehen!
|
|
konbom
      
Beiträge: 36
Win XP Home
Delphi 2005 Personal
|
Verfasst: Fr 06.04.07 21:15
Eigentlich müsstest du bei der ersten auch ne Fehlermeldung kriegen, wenn ComboBox1.Text nicht 'HEB' ist...
Delphi-Quelltext 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
| procedure TForm1.ComboBox1Change(Sender: TObject); var tempStringList : TStrings; i : Integer; begin if ComboBox1.Text = ('HEB') then begin tempStringList := TStringList.Create; tempStringList.LoadFromFile('tab\heb.txt'); tempStringList.Delete(0); tempStringList.Delete(0); for i := 0 to tempStringList.Count -1 do combobox2.Items.Add(copy(tempStringList[i],1,pos(' ',tempStringList[i]))); tempStringList.Free; end; end; |
Delphi-Quelltext 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22:
| procedure TForm1.ComboBox1Change(Sender: TObject); var tempStringList : TStrings; i : Integer; begin if ComboBox1.Text = ('HEB') then begin tempStringList := TStringList.Create; tempStringList.LoadFromFile('tab\heb.txt'); tempStringList.Delete(0); tempStringList.Delete(0); for i := 0 to tempStringList.Count -1 do combobox2.Items.Add(copy(tempStringList[i],1,pos(' ',tempStringList[i]))); tempStringList.Free; end; if ComboBox1.Text = ('HEA') then begin tempStringList := TStringList.Create; tempStringList.LoadFromFile('tab\hea.txt'); tempStringList.Delete(0); tempStringList.Delete(0); for i := 0 to tempStringList.Count -1 do combobox2.Items.Add(copy(tempStringList[i],1,pos(' ',tempStringList[i]))); tempStringList.Free; end; end; |
Du führst nämlich das Create nur aus, wenn die Bedingung erfüllt ist. Wenn sie nicht erfüllt ist, greifst du mit .Loadfromfile auf ne StringListe zu, die es eigentlich noch gar nicht gibt. 
|
|
Cool-Fux 
      
Beiträge: 22
|
Verfasst: Fr 06.04.07 22:35
DANKE!!!!!
Funst bestens.
|
|
Lannes
      
Beiträge: 2352
Erhaltene Danke: 4
Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
|
Verfasst: Fr 06.04.07 23:58
Hallo,
der Code gefällt mir irgendwie nicht, da fehlt eine try...finally-Anweisung und ist auch zu umständlich
Das Ergebnis dürfte das gleiche sein:
Delphi-Quelltext 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19:
| procedure TForm1.ComboBox1Change(Sender: TObject); var tempStringList : TStrings; aFile : String; i : Integer; begin aFile := ExtractFilePath(ParamStr(0))+'tab\'+ComboBox1.Text+'.txt'; if FileExists(aFile) then begin tempStringList := TStringList.Create; try tempStringList.LoadFromFile(aFile); for i := 2 to tempStringList.Count -1 do ComboBox2.Items.Add(Copy(tempStringList[i],1,pos(' ',tempStringList[i]))); finally tempStringList.Free; end; end; end; |
_________________ MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
|
|
Cool-Fux 
      
Beiträge: 22
|
Verfasst: Sa 07.04.07 03:19
Hallo,
vielen Dank für die Procedure.
Die finde ich echt gut, nur müsste man da noch "comboBox2.Items.Clear();"
einbauen. Siehe meinen Code!
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:
| procedure TForm1.ComboBox1Change(Sender: TObject); var tempStringList : TStrings; i : Integer; begin if ComboBox1.Text = ('HEB') then begin comboBox2.Items.Clear(); tempStringList := TStringList.Create; tempStringList.LoadFromFile('tab\heb.txt'); tempStringList.Delete(0); tempStringList.Delete(0); for i := 0 to tempStringList.Count -1 do combobox2.Items.Add(copy(tempStringList[i],1,pos(' ',tempStringList[i]))); tempStringList.Free; end; if ComboBox1.Text = ('HEA') then begin comboBox2.Items.Clear(); tempStringList := TStringList.Create; tempStringList.LoadFromFile('tab\hea.txt'); tempStringList.Delete(0); tempStringList.Delete(0); for i := 0 to tempStringList.Count -1 do combobox2.Items.Add(copy(tempStringList[i],1,pos(' ',tempStringList[i]))); tempStringList.Free; end; if ComboBox1.Text = ('HEM') then begin comboBox2.Items.Clear(); tempStringList := TStringList.Create; tempStringList.LoadFromFile('tab\hem.txt'); tempStringList.Delete(0); tempStringList.Delete(0); for i := 0 to tempStringList.Count -1 do combobox2.Items.Add(copy(tempStringList[i],1,pos(' ',tempStringList[i]))); tempStringList.Free; end; if ComboBox1.Text = ('IPE') then begin comboBox2.Items.Clear(); tempStringList := TStringList.Create; tempStringList.LoadFromFile('tab\ipe.txt'); tempStringList.Delete(0); tempStringList.Delete(0); for i := 0 to tempStringList.Count -1 do combobox2.Items.Add(copy(tempStringList[i],1,pos(' ',tempStringList[i]))); tempStringList.Free; end; end; |
Moderiert von raziel: Delphi-Tags hinzugefügt
|
|
Lannes
      
Beiträge: 2352
Erhaltene Danke: 4
Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
|
Verfasst: Sa 07.04.07 13:33
Hallo,
dann bau es doch ein, am besten vor einfügen der Items. 
_________________ MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
|
|
|