Delphi-PRAXiS
Seite 1 von 2  1 2      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   GUI-Design mit VCL / FireMonkey / Common Controls (https://www.delphipraxis.net/18-gui-design-mit-vcl-firemonkey-common-controls/)
-   -   Delphi Aktion entsprechend ComboBox... (https://www.delphipraxis.net/104627-aktion-entsprechend-combobox.html)

Stern 7. Dez 2007 18:39


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:
if ComboBox1.Text = 'aktion1' then
        qrMain.SQL.Clear;
        qrMain.SQL.Text:= 'SELECT blablabla;';
        qrMain.Active:= True;
        qrMain.open;
Nun habe ich allerdings das Problem, dass die ComboBox sehr umfangreich geworden ist. Mit den If-Abfragen komm ich da natürlich
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

DeddyH 7. Dez 2007 18:40

Re: Aktion entsprechend ComboBox...
 
Über den ItemIndex evtl.?

Stern 7. Dez 2007 18:45

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

DeddyH 7. Dez 2007 18:46

Re: Aktion entsprechend ComboBox...
 
Haargenau.
Delphi-Quellcode:
case ComboBox.ItemIndex of
  0: Machwas;
  1: MachwasAnderes;
  ...
end;

marabu 7. Dez 2007 19:01

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

DeddyH 7. Dez 2007 19:04

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.

Die Muhkuh 7. Dez 2007 19:05

Re: Aktion entsprechend ComboBox...
 
Zitat:

Zitat von DeddyH
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.

Ich denke mal, dass marabu drauf hinweisen wollte, Detlef. Weil aus Steffis Beschreibung etwas derartiges beschreibt. ;-)

Stern 7. Dez 2007 19:05

Re: Aktion entsprechend ComboBox...
 
Kann ich bei in Delphi bei der Case-Abfrage immer nur eine Aktion pro item durchführen?
Also:
Delphi-Quellcode:
case ComboBox.ItemIndex of
  0: eineAktion;
  1: eineAktion;
  ...
end;
Was mache ich dann, wenn ich aber soetwas brauche?
Delphi-Quellcode:
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;
Letzte Doofi-Frage für heute... :oops:

Liebe Grüße
Steffi

Die Muhkuh 7. Dez 2007 19:09

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;
...

DeddyH 7. Dez 2007 19:09

Re: Aktion entsprechend ComboBox...
 
Delphi-Quellcode:
case ComboBox.ItemIndex of
  0: begin
       eineAktion;
       nochneAktion;
     end;
  1: begin
       eineAktion;
       nochneAktion;
     end;
  ...
end;
[edit] Die Kuh war schneller :mrgreen: [/edit]


Alle Zeitangaben in WEZ +1. Es ist jetzt 17:39 Uhr.
Seite 1 von 2  1 2      

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