0

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

1 Answer 1

5

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;
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks i glanced over that one didn't even think twice about it for some reason. Seems to work as needed :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.