开发者

Delphi, olevariants and arrays of strings

开发者 https://www.devze.com 2023-01-08 22:56 出处:网络
i开发者_StackOverflow have an ole Object created with (simple verion) obj := CreateOleObject(\'foo.bar\');

i开发者_StackOverflow have an ole Object created with (simple verion)

obj := CreateOleObject('foo.bar');
obj.OnResult := DoOnResult;

procedure TMyDM.DoOnResult(Res: olevariant);

which all works, the res variable has a function String[] GetAns() which im calling like this

var
 ans: array of string;
begin
 ans := Res.GetAns;
end;

which again works.. except sometimes no array is returned, and then an exception is thrown.

as a temporary solution i have wrapped it in a empty try except block, which i know is bad. I have tried VarIsArray(Res.GetAns) but it still donst work if the result is null

What is the correct way check for the right result?

ps I have no control over the ole Object


Christopher try using the VarIsNull function

procedure TMyDM.DoOnResult(Res: olevariant);
var
 ans: array of string;
begin
 if not VarIsNull(Res) then 
 if not VarIsNull(Res.GetAns) then
 begin
  ans := Res.GetAns;
  //do your stuff

 end;

end;
0

精彩评论

暂无评论...
验证码 换一张
取 消