Delphi: Call a function whose name is stored in a string

后端 未结 10 1357
旧时难觅i
旧时难觅i 2020-12-08 05:30

Is it possible to call a function whose name is stored in a string in Delphi?

10条回答
  •  难免孤独
    2020-12-08 05:35

    Put each function in an Action. Then you can find the Action by name and Execute it

    function ExecuteActionByName(const S: String);
    var
      I: Integer;
    begin
      for I := 0 to MainForm.ComponentCount-1 do
        if (MainForm.Components[I] is TAction)
        and SameText(TAction(MainForm.Components[I]).Name,S) then
        begin
          TAction(MainForm.Components[I]).Execute;
          Break;
        end;
    end;
    

提交回复
热议问题