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

后端 未结 10 1341
旧时难觅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:58

    You can do something like this by crafting one or more classes with published properties that use functions to implement their read and write functionality. The properties can then be discovered using RTTI reflection and referenced, causing the underlying functions to get called.

    Alternatively, you can store function pointers in a table, or even the Object property of TStringList and effectively index them by string name.

    Straight calling of a function by name is not possible in Delphi.

提交回复
热议问题