![]() |
Aktion entsprechend ComboBox...
Hallo,
ich habe eine ComboBox, die über eine php-Datei gefüllt wird. Soweit funktioniert das auch. Nun würde ich noch gerne eine Möglichkeit haben, in Abhängigkeit des ausgewählten Items eine bestimmte aktion auszuführen. Bislang hätte ich das so gemacht:
Delphi-Quellcode:
Nun habe ich allerdings das Problem, dass die ComboBox sehr umfangreich geworden ist. Mit den If-Abfragen komm ich da natürlich
if ComboBox1.Text = 'aktion1' then
qrMain.SQL.Clear; qrMain.SQL.Text:= 'SELECT blablabla;'; qrMain.Active:= True; qrMain.open; nicht weit, da so in jedem Fall nur die letzte Aktion der ComboBox ausgeführt wird. Warum die IF-Abfrage übergangen wird, weiß ich nicht. Wie könnte man noch abfragen, welches item ausgewählt wurde? Liebe Grüße Steffi |
Re: Aktion entsprechend ComboBox...
Über den ItemIndex evtl.?
|
Re: Aktion entsprechend ComboBox...
Ok, bei 25 Items dann am besten über eine case-Abfrage?
Entschuldigt bitte diese dummen Fragen, aber ich bin noch ziemlich neu und nicht so wirklich firm, was hier am schnellsten von der performance her wäre... :oops: Liebe Grüße Steffi |
Re: Aktion entsprechend ComboBox...
Haargenau.
Delphi-Quellcode:
case ComboBox.ItemIndex of
0: Machwas; 1: MachwasAnderes; ... end; |
Re: Aktion entsprechend ComboBox...
Hallo Steffi,
der IF-Abfrage folgt ein einzelnes Statement, da du den BEGIN-END-Block vergessen hast. Grundsätzlich sollte der Wechsel des Items in einer ComboBox keine Aktion auslösen, die einen spürbaren Zeitverbrauch mit sich bringt. Grüße vom marabu |
Re: Aktion entsprechend ComboBox...
Hi marabu,
so gut gemeint und richtig Dein Rat auch ist, ich habe nirgends lesen können, dass sie direkt im OnChange-Ereignis eine Aktion auslösen möchte. |
Re: Aktion entsprechend ComboBox...
Zitat:
|
Re: Aktion entsprechend ComboBox...
Kann ich bei in Delphi bei der Case-Abfrage immer nur eine Aktion pro item durchführen?
Also:
Delphi-Quellcode:
Was mache ich dann, wenn ich aber soetwas brauche?
case ComboBox.ItemIndex of
0: eineAktion; 1: eineAktion; ... end;
Delphi-Quellcode:
Letzte Doofi-Frage für heute... :oops:
case ComboBox1.ItemIndex of
0:qrMain.SQL.Clear; qrMain.SQL.Text:= 'SELECT blabla1;'; qrMain.Active:= True; qrMain.open; brake; 1:qrMain.SQL.Clear; qrMain.SQL.Text:= 'SELECT blabla2;'; qrMain.ParamByName('jahr').asString := Jahr; qrMain.Active:= True; qrMain.open; Liebe Grüße Steffi |
Re: Aktion entsprechend ComboBox...
Hi Steffi,
nein, Du kannst natürlich auch mehr ausführen:
Delphi-Quellcode:
case ComboBox1.ItemIndex of
0: begin { Dein Code } end; 1: begin { Dein Code } end; ... |
Re: Aktion entsprechend ComboBox...
Delphi-Quellcode:
[edit] Die Kuh war schneller :mrgreen: [/edit]
case ComboBox.ItemIndex of
0: begin eineAktion; nochneAktion; end; 1: begin eineAktion; nochneAktion; end; ... end; |
Alle Zeitangaben in WEZ +1. Es ist jetzt 19:59 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz