利用反射就适合做脚本了
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.Buttons, Vcl.Grids, Vcl.Samples.Calendar,
Vcl.CategoryButtons, Vcl.CheckLst, Vcl.ExtCtrls, System.Rtti;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
TBot = class
HP: DWORD;
function AddHP(i: DWORD): DWORD;
end;
var
Form1: TForm1;
Bot: TBot;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
t: TRttiType;
f: TRttiMethod;
r: TValue; //TRttiMethod.Invoke 的返回类型
begin
t := TRttiContext.Create.GetType(TBot);
f:= t.GetMethod('AddHP');
r := f.Invoke(Bot,[123]);
ShowMessage(r.ToString);
end;
{ TBot }
function TBot.AddHP(i: DWORD): DWORD;
begin
HP := HP + i;
Result := HP;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Bot := TBot.Create;
end;
end.
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.Buttons, Vcl.Grids, Vcl.Samples.Calendar,
Vcl.CategoryButtons, Vcl.CheckLst, Vcl.ExtCtrls, System.Rtti;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
TBot = class
HP: DWORD;
function AddHP(i: DWORD): DWORD;
end;
var
Form1: TForm1;
Bot: TBot;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
t: TRttiType;
f: TRttiMethod;
r: TValue; //TRttiMethod.Invoke 的返回类型
begin
t := TRttiContext.Create.GetType(TBot);
f:= t.GetMethod('AddHP');
r := f.Invoke(Bot,[123]);
ShowMessage(r.ToString);
end;
{ TBot }
function TBot.AddHP(i: DWORD): DWORD;
begin
HP := HP + i;
Result := HP;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Bot := TBot.Create;
end;
end.
浙公网安备 33010602011771号