函数指针应该也是一个指针把,所以我想用int型来保存其地址数据。
可是好像强制转换不行,我用内存拷贝也不行。
大虾们指点一下,目的就是用通过一个整数来传递函数指针,达到函数的调用和实现分离。
//------------------------------------------------
type
PNotifyMsgs = procedure of object;var
iTest: Integer;
pFunc1,pFunc2 : PNotifyMsgs;
begin
pFunc1 := aProcedure;//将一个现有函数赋给它
CopyMemory(@iTest, @pFunc1, SizeOf(Integer));
CopyMemory(@pFunc2, @iTest, SizeOf(Integer));
pFunc2;
end;
可是好像强制转换不行,我用内存拷贝也不行。
大虾们指点一下,目的就是用通过一个整数来传递函数指针,达到函数的调用和实现分离。
//------------------------------------------------
type
PNotifyMsgs = procedure of object;var
iTest: Integer;
pFunc1,pFunc2 : PNotifyMsgs;
begin
pFunc1 := aProcedure;//将一个现有函数赋给它
CopyMemory(@iTest, @pFunc1, SizeOf(Integer));
CopyMemory(@pFunc2, @iTest, SizeOf(Integer));
pFunc2;
end;
解决方案 »
- 请问Delphi编写下载文件的工具,如何实现"加载条"?
- delphi &符号的问题
- 哪位高手能告诉我有关paradox7数据库的相关知识和用法
- hSession := InternetOpen('MyApp', 。。。。。。。),怎样取得webbrowser的hSession?
- 我想从客户端传递字符串到服务器端,请问怎样做呢??????
- 关于treeview问题,改变节点text的颜色!!
- 保证你现在和未来不失业的十种关键技术-一家之言(转载)欢迎讨论
- 最后一个问题,没分了,全给第一个答对的,有关SQLSERVER
- Delphi简单问题
- 在d5中怎样得到当前应用程序的目录???
- 求fastreport可用版本,谢谢了(D7)
- 读取MAC物理地址
TForm1 = class(TForm)
btn1: TButton;
procedure btn1Click(Sender: TObject);
private
{ Private declarations }
procedure Test;
public
{ Public declarations }
end;type
PNotifyMsgs = procedure of object;
var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.btn1Click(Sender: TObject);
var
iTest: Integer;
pFunc1,pFunc2 : PNotifyMsgs;
begin
pFunc1 :=test;//将一个现有函数赋给它
iTest:=Integer(@pFunc1);
if Pointer(iTest)<>nil then begin
pFunc1;
end;
end;procedure TForm1.Test;
begin
ShowMessage('OK');
end;
type
TForm1 = class(TForm)
......
published
{ Public declarations } function CheckMP3(s:string):boolean;
end;function TForm1.CheckMP3(s:String):boolean;
begin
if pos('.mp3',lowercase(s))<>0 then Result:=true else Result:=false;
end;procedure TForm1.BtnClick(Sender: TObject);
var CheckFunc: function(s:string):boolean of object;
begin
TMethod(CheckFunc).Code :=MethodAddress('CheckMP3');
TMethod(CheckFunc).Data := self ;
if CheckFunc('1.mp3') then ShowMessage('ok');
end;
怎么再把这个整数iTest赋给另一个函数指针pFunc2
??
从这个例子看好像一个整数标识不了一个函数指针
需要两个?
TForm1 = class(TForm)
btn1: TButton;
procedure btn1Click(Sender: TObject);
private
{ Private declarations }
procedure Test;
public
{ Public declarations }
end;type
PNotifyMsgs = procedure of object;
var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.btn1Click(Sender: TObject);
var
iTest: Integer;
pFunc1,pFunc2 : PNotifyMsgs;
begin
pFunc1 :=test;//将一个现有函数赋给它
iTest:=Integer(@pFunc1);
if Pointer(iTest)<>nil then begin
@pFunc2:=Pointer(iTest); //就这样了, 会不会把你搞晕头
pFunc2;
end;
end;procedure TForm1.Test;
begin
ShowMessage('OK');
end;
这句真得很难理解~~~