用指针的话,判断是否为nil 用整数的话,判断是否为0function DllFunc() : Pointer; if DllFunc=nil thenfunction DllFunc() : Integer; if DllFunc=0 then
不能用pchar,要用widestring,不存在null,在delphi里空的表示是 nil,这个不能针对字符串,针对某一对象,比如按钮是否存在 用 if button1=nil then ..... 也就是说字符串只能用 if str='' then ....
给个用PChar的例子:function F1: PChar; begin Result := nil; end;function F2: PChar; begin Result := 'Hello'; end;procedure TForm1.Button1Click(Sender: TObject); var A : PChar; begin GetMem(A, 128); A := F1; if A <> nil then ShowMessage(A); A := F2; if A <> nil then ShowMessage(A); end;
用整数的话,判断是否为0function DllFunc() : Pointer;
if DllFunc=nil thenfunction DllFunc() : Integer;
if DllFunc=0 then
也就是说字符串只能用 if str='' then ....
begin
Result := nil;
end;function F2: PChar;
begin
Result := 'Hello';
end;procedure TForm1.Button1Click(Sender: TObject);
var
A : PChar;
begin
GetMem(A, 128);
A := F1;
if A <> nil then ShowMessage(A);
A := F2;
if A <> nil then ShowMessage(A);
end;