unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type TForm1 = class(TForm) Button1: TButton; procedure aaa; procedure Button1Click(Sender: TObject); private { Private declarations } Function call:integer; public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm}{ TForm1 }procedure TForm1.aaa; begin showmessage( 'hello world' ); end;procedure TForm1.Button1Click(Sender: TObject); begin call; end;function TForm1.call: integer; var PAddr: Pointer; begin try PAddr := TForm1.MethodAddress('aaa'); if PAddr <> nil then asm mov eax, TForm1 call PAddr mov Result, eax end; except end; end;end.
procedure ProcName; begin Application.MessageBox('ddddddddd', 'dddd', MB_OK); end;procedure TForm1.btn1Click(Sender: TObject); var Proc: TProcedure; begin Proc := @ProcName; Proc; end;
上面的理解错意思了,简单更正一下:procedure TForm1.btn1Click(Sender: TObject); var Proc: TProcedure; begin Proc := TForm1.MethodAddress('ProcName'); if Assigned(Proc) then Proc; end;
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
procedure aaa;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
Function call:integer;
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}{ TForm1 }procedure TForm1.aaa;
begin
showmessage( 'hello world' );
end;procedure TForm1.Button1Click(Sender: TObject);
begin
call;
end;function TForm1.call: integer;
var
PAddr: Pointer;
begin
try
PAddr := TForm1.MethodAddress('aaa');
if PAddr <> nil then
asm
mov eax, TForm1
call PAddr
mov Result, eax
end;
except
end;
end;end.
begin
Application.MessageBox('ddddddddd', 'dddd', MB_OK);
end;procedure TForm1.btn1Click(Sender: TObject);
var
Proc: TProcedure;
begin
Proc := @ProcName;
Proc;
end;
var
Proc: TProcedure;
begin
Proc := TForm1.MethodAddress('ProcName');
if Assigned(Proc) then Proc;
end;