Einzelnen Beitrag anzeigen

Benutzerbild von Neutral General
Neutral General

Registriert seit: 16. Jan 2004
Ort: Bendorf
5.219 Beiträge
 
Delphi 10.2 Tokyo Professional
 
#2

AW: Dynamischer Methodenaufruf

  Alt 20. Apr 2018, 12:59
Benutz ein TDictionary<string, TDoWertProc>
Delphi-Quellcode:
type
  TDoWertProc = procedure(AParam1: Integer; AParam2: TObject) of object; // Natürlich Parameter anpassen

var doWertDict: TDictionary<string, TDoWertProc>;
begin
  // 1x Initialisieren:
  doWertDict := TDictionary<string, TDoWertProc>.Create;
  doWertDict.Add('Wert1', DoWert1);
  doWertDict.Add('Wert2', DoWert2);

  // Aufruf
  doWertDict[key](param1, param2);
end;
Michael
"Programmers talk about software development on weekends, vacations, and over meals not because they lack imagination,
but because their imagination reveals worlds that others cannot see."

Geändert von Neutral General (20. Apr 2018 um 13:03 Uhr)
  Mit Zitat antworten Zitat