Delphi中使用@取函数地址的问题
2010-02-09 09:31
253 查看
例如以下代码:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,Dialogs;
type
TForm1 = class(TForm)
procedure one();
function two(x,y:integer):integer;
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.one();
var
p : pointer;
begin
p:=@two;
end;
function TForm1.two(x,y:integer):integer;
begin
Result:=x+y;
end;
end.
在Delphi5中,没有任何问题,到了delphi7、2007、2009中就会报错:需要变量(Delphi6没试)
原因是新版本中要求返回函数地址的函数必须是全局函数,所以程序要改成这样:
................................
var
Form1: TForm1;
function two(x,y:integer):integer;
................................
function two(x,y:integer):integer;
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,Dialogs;
type
TForm1 = class(TForm)
procedure one();
function two(x,y:integer):integer;
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.one();
var
p : pointer;
begin
p:=@two;
end;
function TForm1.two(x,y:integer):integer;
begin
Result:=x+y;
end;
end.
在Delphi5中,没有任何问题,到了delphi7、2007、2009中就会报错:需要变量(Delphi6没试)
原因是新版本中要求返回函数地址的函数必须是全局函数,所以程序要改成这样:
................................
var
Form1: TForm1;
function two(x,y:integer):integer;
................................
function two(x,y:integer):integer;
相关文章推荐
- Delphi中使用@取函数地址的问题(转)
- Delphi中使用@取函数地址的问题
- 在Delphi中使用ShellExecute(handle, 'open', PChar(fname),nil, nil, SW_HIDE)函数应注意的问题
- Delphi使用C++库,向库中函数传递回调函数指针的问题解决
- Oracle中使用Table()函数解决For循环中不写成 in (l_idlist)形式的问题
- ArcGIS——数据库空间SQL(一、oracle中使用sql空间查询及st_astext等函数出错问题)
- 关于PHP程序使用file_get_content()函数进行抓取PHP程序与smarty结合编译过程中产生的静态文件,抓取不了?连接超时?(地址映射)
- 约瑟夫环问题的PHP实现 使用PHP数组内部指针操作函数
- 使用C++标准库sort自定义比较函数导致死循环问题
- Delphi 中的 IfThen 函数 - 回复 "深挖洞、广积粮" 的问题
- Java Split()函数使用中一些要注意的问题
- Delphi 使用双缓冲解决图片切换时的闪烁问题 good
- 【急】Delphi 使用MSMQ时的编码问题
- 使用MATLAB自带函数求解二次特征值问题
- 在使用了MasterPage后,FindControl()函数引起的问题
- 新浪微博API使用初步介绍——解决回调地址的问题
- js使用立即调用的函数表达式创建局部作用域问题
- [转]PHP使用empty检查函数返回结果时报Fatal error: Can't use function return value in write context的问题
- 5、数组地址增长方向和函数调用相关问题
- 使用SQL SERVER 内部函数进行密码加密和校验小问题