views:

118

answers:

1

i 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

+5  A: 

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;
RRUZ
Thanks i glanced over that one didn't even think twice about it for some reason. Seems to work as needed :)
Christopher Chase