Christopher Chase
Christopher Chase

Reputation: 2890

Delphi, olevariants and arrays of strings

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

Upvotes: 0

Views: 3098

Answers (1)

RRUZ
RRUZ

Reputation: 136381

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;

Upvotes: 5

Related Questions