龙丹:
请斧正:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TMyProcMethod=procedure of object;
TMyFuncMethod=function:boolean of object;
type
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
Label2: TLabel;
procedure Button1Click(Sender: TObject);
private
Procedure MyProc;
Function MyFunc:Boolean;
procedure AfterMyFunc;
function GetMyProcAddr(M:TMyProcMethod)
ointer;
function GetMyFuncAddr(M:TMyFuncMethod)
ointer;
function GetCodeSize(PB,PE
ointer):LongInt;
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function TForm1.GetMyProcAddr(M:TMyProcMethod)
ointer;
begin
Result:=TMethod(M).Code;
end;
function TForm1.GetMyFuncAddr(M:TMyFuncMethod)
ointer;
begin
Result:=TMethod(M).Code;
end;
procedure TForm1.MyProc;
begin
Showmessage('Thank You');
Showmessage('Thank You');
end;
function TForm1.MyFunc: Boolean;
begin
Showmessage('Thank You');
Showmessage('Thank You');
Result:=True;
end;
procedure TForm1.AfterMyFunc;
begin
Showmessage('Thank You');
Showmessage('Thank You');
end;
function TForm1.GetCodeSize(PB, PE: Pointer):LongInt;
begin
Result:=LongInt(PE)-LongInt(PB);
end;
procedure TForm1.Button1Click(Sender: TObject);
Var
S:String;
begin
S:=IntToStr(GetCodeSize(GetMyProcAddr(MyProc),GetMyFuncAddr(MyFunc)));
S:=S+' '+IntToStr(GetCodeSize(GetMyFuncAddr(MyFunc),GetMyProcAddr(AfterMyFunc)));
Label1.Caption:=S;//结果44 44 为什么前指针-后指针=正值,相反的=负值?
S:=IntToStr(GetCodeSize(GetMyFuncAddr(MyFunc),GetMyProcAddr(MyProc)));
S:=S+' '+IntToStr(GetCodeSize(GetMyProcAddr(AfterMyFunc),GetMyFuncAddr(MyFunc)));
Label2.Caption:=S;//结果-44 -44
end;
end.