求助null和nil和0
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”应该是可以验证的,为什么还会报错呢?请求牛牛们指示