Mozes pomocu RTTI-ja
Code:
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
public
procedure NekaMetoda(const AMessage: String);
end;
var
Form1: TForm1;
implementation
uses
System.Rtti;
{$R *.dfm}
function ExecMethod(const AClass: TClass; const AMethod: String; const AArgs: array of TValue): Boolean;
var
r: TRttiContext;
t: TRttiType;
m: TRttiMethod;
begin
t := R.GetType(AClass);
m := t.GetMethod(AMethod);
if Assigned(m) then
begin
m.Invoke(AClass.Create, AArgs);
Exit(TRUE);
end;
Exit(FALSE);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
ExecMethod(TForm1, 'NekaMetoda', ['neka poruka']);
end;
procedure TForm1.NekaMetoda(const AMessage: String);
begin
ShowMessage(AMessage);
end;
end.