Autor Beitrag
Cool-Fux
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 22



BeitragVerfasst: 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
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Do 29.03.07 23:21 
Moin und :welcome: 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: :idea:
ausblenden 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
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 105

Windows 7, Vista, Ubuntu
HTML,CSS,PHP,Delphi 7
BeitragVerfasst: 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 :wink:

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 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 22



BeitragVerfasst: 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:
ausblenden 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 user profile iconChristian S.: Delphi-Tags hinzugefügt
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mo 02.04.07 23:15 
Moin!

Was ist denn nun mit deinem Code, funktioniert daran irgendwas nicht, wo ist das Problem? :gruebel:

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Cool-Fux Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 22



BeitragVerfasst: Di 03.04.07 19:39 
Hallo,

diese Procedure funst:
ausblenden 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'); //Datei laden
     tempStringList.Delete(0); // Zeile 'NENN H B S T T1 R R2 D1 W1 W3 A OFL IY WY Iz Wz W2 NEIGW ' löschen !
     tempStringList.Delete(0); // Zeile' --------------------' löschen !
     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:
ausblenden 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'); //Datei laden
     tempStringList.Delete(0); // Zeile 'NENN H B S T T1 R R2 D1 W1 W3 A OFL IY WY Iz Wz W2 NEIGW ' löschen !
     tempStringList.Delete(0); // Zeile' --------------------' löschen !
     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'); //Datei laden
     tempStringList.Delete(0); // Zeile 'NENN H B S T T1 R R2 D1 W1 W3 A OFL IY WY Iz Wz W2 NEIGW ' löschen !
     tempStringList.Delete(0); // Zeile' --------------------' löschen !
     for i := 0 to tempStringList.Count -1 do combobox2.Items.Add(copy(tempStringList[i],1,pos(' ',tempStringList[i])));
     tempStringList.Free;
end;


Gruß

Moderiert von user profile iconChristian S.: Delphi-Tags hinzugefügt
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Di 03.04.07 21:00 
Moin!

user profile iconCool-Fux hat folgendes geschrieben:
Und bei dieser erhalte ich eine Fehlermeldung:

Und... welche Fehlermeldung... könnte das wohl sein... und vor allem... wo? :gruebel: ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Cool-Fux Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 22



BeitragVerfasst: Fr 06.04.07 18:59 
Hallo,
wir mal die Fehlermeldung als Anlage:
Einloggen, um Attachments anzusehen!
konbom
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 36

Win XP Home
Delphi 2005 Personal
BeitragVerfasst: Fr 06.04.07 21:15 
Eigentlich müsstest du bei der ersten auch ne Fehlermeldung kriegen, wenn ComboBox1.Text nicht 'HEB' ist...
ausblenden 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'); //Datei laden
     tempStringList.Delete(0); // Zeile 'NENN H B S T T1 R R2 D1 W1 W3 A OFL IY WY Iz Wz W2 NEIGW ' löschen !
     tempStringList.Delete(0); // Zeile' --------------------' löschen !
     for i := 0 to tempStringList.Count -1 do combobox2.Items.Add(copy(tempStringList[i],1,pos(' ',tempStringList[i])));
     tempStringList.Free;
  end;
end;


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:
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'); //Datei laden
     tempStringList.Delete(0); // Zeile 'NENN H B S T T1 R R2 D1 W1 W3 A OFL IY WY Iz Wz W2 NEIGW ' löschen !
     tempStringList.Delete(0); // Zeile' --------------------' löschen !
     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'); //Datei laden
     tempStringList.Delete(0); // Zeile 'NENN H B S T T1 R R2 D1 W1 W3 A OFL IY WY Iz Wz W2 NEIGW ' löschen !
     tempStringList.Delete(0); // Zeile' --------------------' löschen !
     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 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 22



BeitragVerfasst: Fr 06.04.07 22:35 
DANKE!!!!!
Funst bestens.
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: 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 :wink:
Das Ergebnis dürfte das gleiche sein:
ausblenden 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
  //ExtractFilePath(ParamStr(0)) = Anwendungsverzeichnis!
  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//ab 2te Zeile, delete entfällt
      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 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 22



BeitragVerfasst: 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!

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:
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'); //Datei laden
     tempStringList.Delete(0); // Zeile 'NENN H B S T T1 R R2 D1 W1 W3 A OFL IY WY Iz Wz W2 NEIGW ' löschen !
     tempStringList.Delete(0); // Zeile' --------------------' löschen !
     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'); //Datei laden
     tempStringList.Delete(0); // Zeile 'NENN H B S T T1 R R2 D1 W1 W3 A OFL IY WY Iz Wz W2 NEIGW ' löschen !
     tempStringList.Delete(0); // Zeile' --------------------' löschen !
     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'); //Datei laden
     tempStringList.Delete(0); // Zeile 'NENN H B S T T1 R R2 D1 W1 W3 A OFL IY WY Iz Wz W2 NEIGW ' löschen !
     tempStringList.Delete(0); // Zeile' --------------------' löschen !
     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'); //Datei laden
     tempStringList.Delete(0); // Zeile 'NENN H B S T T1 R R2 D1 W1 W3 A OFL IY WY Iz Wz W2 NEIGW ' löschen !
     tempStringList.Delete(0); // Zeile' --------------------' löschen !
     for i := 0 to tempStringList.Count -1 do combobox2.Items.Add(copy(tempStringList[i],1,pos(' ',tempStringList[i])));
     tempStringList.Free;
  end;
end;


Moderiert von user profile iconraziel: Delphi-Tags hinzugefügt
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: Sa 07.04.07 13:33 
Hallo,

dann bau es doch ein, am besten vor einfügen der Items. :wink:

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