Einzelnen Beitrag anzeigen

Benutzerbild von Sir Rufo
Sir Rufo

Registriert seit: 5. Jan 2005
Ort: Stadthagen
9.454 Beiträge
 
Delphi 10 Seattle Enterprise
 
#4

AW: Combobox Werte sollen Action1.execute, Action2.execute ausführen

  Alt 31. Dez 2011, 17:50
Wenn du dir deinen letzten Thread aufmerksam durchgelesen hättest und ein wenig Transferleistung dazu packst könntest du auf folgende Lösung kommen:
Delphi-Quellcode:
procedure TForm1.FormCreate( Sender : TObject );
begin
  // Items der ComboBox vorbelegen
  ComboBox1.Items.AddObject( Action1.Caption, Action1 );
  ComboBox1.Items.AddObject( Action2.Caption, Action2 );
end;

procedure TForm1.ComboBox1Change( Sender : TObject );
begin
  if
    Assigned( ComboBox1.Items.Objects[ ComboBox1.ItemIndex ] ) and
    ( ComboBox1.Items.Objects[ ComboBox1.ItemIndex ] is TAction )
  then
    TAction( ComboBox1.Items.Objects[ ComboBox1.ItemIndex ] ).Execute;
end;
Welchen Text man beim Füllen der Items verwendet ist natürlich völlig egal, Hauptsache, man packt eine Action (oder eine Ableitung derselbigen) als Object dazu.
Kaum macht man's richtig - schon funktioniert's
Zertifikat: Sir Rufo (Fingerprint: ‎ea 0a 4c 14 0d b6 3a a4 c1 c5 b9 dc 90 9d f0 e9 de 13 da 60)
  Mit Zitat antworten Zitat