Autor Beitrag
hansg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 168

Win XP Professional SP3, Vista Ultimate 32 SP1
Delphi 6 Professional
BeitragVerfasst: Do 10.04.03 15:15 
Hallo zusammen,
ich habe eine Combobox mit 6 Einträgen.
Wenn ich auf einen Button drücke sollen in dieser dann andere z.B. 5 Eintrage stehen .
Wie stelle ich sowas an?

_________________
Gruß Hans
Klabautermann
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Veteran
Beiträge: 6366
Erhaltene Danke: 60

Windows 7, Ubuntu
Delphi 7 Prof.
BeitragVerfasst: Do 10.04.03 15:40 
Hallo,

die Liste wird von einem tStrings-Objekt repräsentiert.
Daher geht es einfach so:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
  ComboBox1.Items.Clear;
  ComboBox1.Items.Add('Zeile 1');
  ComboBox1.Items.Add('Zeile 2');
  ComboBox1.Items.Add('Zeile 3');
  ComboBox1.Items.Add('Zeile 4');
  ComboBox1.Items.Add('Zeile 5');

Wenn du unter tStrings oder auch tStringList in die Delphi-Hilfe guckst kannst du noch andere, Tippfreundlicher, lösungen für dein Problem finden.

Gruß
Klabautermann
raven_22
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 95

Win XP pro
D7 Enterprise
BeitragVerfasst: Do 12.02.04 16:27 
Oder auch so ! :D

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
procedure TForm1.Button1Click(Sender: TObject);
Var I:integer;
begin
Combobox1.Clear;
for I := 1 to 5 do
Combobox1.Items.Add('Zeile ' +inttostr(i));
end;


Gruß raven 8)

_________________
---_-= raven_22 =-_---
Chatfix
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1583
Erhaltene Danke: 10

Win 10, Win 8, Win 7, Win Vista, Win XP
VB.net (VS 2015), MsSQL (T-SQL), HTML, CSS, PHP, MySQL
BeitragVerfasst: Do 12.02.04 16:50 
Naja die Schleife kommt nur in Frage wenn er immer das gleiche reinschreiben will...

wenn er z.B. Länder drin hat funzt das nich so *g* dann schon eher wie klabautermann...

ComboBox1.Clear ist allerdings hilfreich wenn man komplett von vorn eintragen möchte, und nicht an vorhandes anhängen will

_________________
Gehirn: ein Organ, mit dem wir denken, daß wir denken. - Ambrose Bierce
raven_22
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 95

Win XP pro
D7 Enterprise
BeitragVerfasst: Do 12.02.04 17:27 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
procedure TForm1.Button1Click(Sender: TObject);
Var I:integer;
    StrList:TStringList;
begin
StrList:=TStringList.Create;
StrList.CommaText:='So kann man auch unterschiedliche Inhalte einfügen ! :-)';
Combobox1.Items:=StrList;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
Combobox1.Clear;
end;


Dann halt so ! :D

Gruß raven 8)

_________________
---_-= raven_22 =-_---
Andreas L.
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1703
Erhaltene Danke: 25

Windows Vista / Windows 10
Delphi 2009 Pro (JVCL, DragDrop, rmKlever, ICS, EmbeddedWB, DEC, Indy)
BeitragVerfasst: Di 17.02.04 21:15 
raven_22 hat folgendes geschrieben:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
procedure TForm1.Button1Click(Sender: TObject);
Var I:integer;
    StrList:TStringList;
begin
StrList:=TStringList.Create;
StrList.CommaText:='So kann man auch unterschiedliche Inhalte einfügen ! :-)';
Combobox1.Items:=StrList;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
Combobox1.Clear;
end;


Dann halt so ! :D

Gruß raven 8)


Hi,
das ist nicht ganz richtig *g*

ausblenden Delphi-Quelltext
1:
2:
3:
4:
procedure TForm1.FormCreate(Sender: TObject);
begin
Combobox1.Clear;
end;


Meines Wissens nach wird in der FormCreate-Procedure das Formular und die Komponenten erst erstellt. Und wenn die ComboBox noch nicht erstellt wurde kannst du die auch nicht verändern. Wohl eher FormActivate oder FormShow müsste da verwendet werden. achtung, in den 2 von mir genannten proceduren darf die iegenschaft visible oder show nicht verändert werden :-)

Hoffe mein text entspricht der Wahrheit :-)

Greetz
raven_22
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 95

Win XP pro
D7 Enterprise
BeitragVerfasst: Di 17.02.04 22:40 
Du magst ja Recht haben, aber ich benutze Delphi 7 Enterprise.
Bei den Vorgängerversionen, war es vielleicht noch so.
Da ich nun aber mit Delphi 7 Enterprise angefangen habe, kenne ich mich mit den Vorgängern nicht aus.
Möglicherweise hast du Recht, du kannst aber auch auf dem digitalen Holzweg sein.
Du kannst ja mal den folgenden Code testen, bei mir Funzt alles was ich poste.

Gruß raven 8)

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
...
procedure TForm1.FormCreate(Sender: TObject);
Var Combobox1 : TComboBox;
    StrList : TStringList;

begin
Combobox1 := TComboBox.Create(self);
Combobox1.Parent := Form1;
Combobox1.Clear;

StrList := TStringList.Create;
StrList.CommaText := 'So kann man auch unterschiedliche Inhalte einfügen ! ';
Combobox1.Items := StrList;
end;

_________________
---_-= raven_22 =-_---
Klabautermann
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Veteran
Beiträge: 6366
Erhaltene Danke: 60

Windows 7, Ubuntu
Delphi 7 Prof.
BeitragVerfasst: Mi 18.02.04 10:07 
Hi,
onlinehome hat folgendes geschrieben:
Meines Wissens nach wird in der FormCreate-Procedure das Formular und die Komponenten erst erstellt.

das kann ich nicht bestätigen. Automatisch erzeugtew Komponenten stehen im Form Create bereitrs zur verfügung (auch von Delphi 7), sie werde also vor FormCreate erzeugt. Man kann also problemlos im FormCreate mit den Komponenten dieses Formulars Arbeiten.
Anders sieht es mit Komponenten anderer Formulare aus. Wenn du aus der OnCreate von Form1 auf Komponenten von Form2 zugreifen möchtest, dann kann es sein das Form2 und damit seine Komponenten noch nicht erzeugt sind. FormCreate ist also kein Ort um seine Komplette Anwendung zu initialisieren ;).

Gruß
Klabautermann
raven_22
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 95

Win XP pro
D7 Enterprise
BeitragVerfasst: Mi 18.02.04 18:50 
Beim heiligen Klabautermann, du hast vollkommen Recht ! :D
Ich habe das auch schon feststellen müssen.
Die FormCreate-Procedure ist sehr gut zum ausführen von Funktionen und so.
Beispielsweiße das laden von Daten, beim Programmstart.
Programmieren ist ein schöner Zeitvertreib, besonders bei der Fehlersuche. :wink:
Hat einer von euch mal in VS.NET geprogt ?
Ich finde das Delphi, viel besser ist als VS.NET. :D

Gruß vom raven 8)

_________________
---_-= raven_22 =-_---