求助null和nil和0

yibing55555 2011-03-02 03:28:54
procedure TForm1.Button1Click(Sender: TObject);
begin
hInst:=LoadLibrary('dll\ShowMe.dll');
if hInst>0 then
try
begin
DynaShow:=GetProcAddress(hInst,'ShowTest');
//if DynaShow<>nil then {失败}
//if DynaShow<>0 then {失败}
if DynaShow<>null then {成功}

DynaShow
else
begin
MessageBox(handle,'函数加载失败!','警告',64);
exit;
end;
end;
finally
FreeLibrary(hInst);
end
else
begin
MessageBox(Handle,'DLL加载失败!','警告',64);
exit;
end;

end;
红字部分前两种会报“Incompatible types”错误,第三种就可以编译成功。
据小菜得知:在Delphi中null是函数,是验证宏是否存在的一个函数,nil是空类型指针,0就是整数0了。
根据追查GetProcAddress()函数返回值是FARPROC,而在Windows单元中FARPROC定义为Pointer类型,即FARPROC = Pointer,一次推理“DynaShow<>null”应该是可以验证的,为什么还会报错呢?请求牛牛们指示
...全文
196 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
CaiBirdy 2011-03-11
  • 打赏
  • 举报
回复
if Pointer(@DynaShow)<>nil then
if Integer(@DynaShow)<>0 then
yibing55555 2011-03-11
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 kye_jufei 的回复:]
這要看DynaShow的類型而定。。
[/Quote]
DynaShow 是一个过程。DynaShow:=Procedure ;stdcall;
kye_jufei 2011-03-11
  • 打赏
  • 举报
回复
這要看DynaShow的類型而定。。
haitao 2011-03-11
  • 打赏
  • 举报
回复
使用 assigned(@xxx) ?
Mit1208 2011-03-02
  • 打赏
  • 举报
回复
DynaShow 应该是一个声明的一个动态链接文件内的函数!
lw19860412 2011-03-02
  • 打赏
  • 举报
回复
NULL 是字符串为空 NIL 是指针为空 NULL 是无值无类型 NIL 是空指针型
yibing55555 2011-03-02
  • 打赏
  • 举报
回复
环境:XP_Sp3+Delphi7
Jekhn 2011-03-02
  • 打赏
  • 举报
回复
if DynaShow<>null then
这样可以成功太奇怪了,
if DynaShow <> nil then 成功
if DynaShow > 0 then 成功
if Assigned(DynaShow) then 成功
我觉得这样都可以,不明白你的怎么不行
dinoalex 2011-03-02
  • 打赏
  • 举报
回复
http://msdn.microsoft.com/en-us/library/ms683212(v=vs.85).aspx

If the function fails, the return value is NULL. To get extended error information, call GetLastError.


一般这样用:

@DynaShow:=GetProcAddress(hInst,'ShowTest');
if Assigned(DynaShow) then DynaShow..
bdmh 2011-03-02
  • 打赏
  • 举报
回复
你的DynaShow是什么类型

1,183

社区成员

发帖
与我相关
我的任务
社区描述
Delphi Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧