Delphi finds an instance of a function based on a string and executes it
Keyword : MethodAddress: Get the address of the method. This method needs to be published.
Example code:
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TShowInfo = procedure(info:string) of object; //Declare a procedure type, the parameters are consistent with ShowInfo TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } published procedure ShowInfo(info: string); end; var Form1: TForm1; implementation {$R *.dfm} { TForm1 } procedure TForm1.ShowInfo(info: string); begin ShowMessage(info); end; procedure TForm1. Button1Click(Sender: TObject); var s:TShowInfo; begin @s := MethodAddress('ShowInfo'); //Get the address of ShowInfo if @s <> nil then //If not empty begin s('People's Republic of China'); //Execute end; end; end.
If you have any questions, please leave a message or go to the community of this site to communicate and discuss. Thank you for reading. I hope it can help everyone. Thank you for your support of this site!