I am writing a pascal function using Inno setup studio which checks if an object is null and does something
so far I have:
XMLDocument.setProperty('SelectionLanguage', 'XPath');
XMLNode := XMLDocument.selectSingleNode(APath);
if (XMLNode=Null) then
begin
//do stuff
End
Else
//do other stuff
End
but I keep getting invalid variant operation
error.
How do I check if an object is null in Inno Setup Pascal Script code?
For checking if a Variant
is NULL
use the VarIsNull
function:
if VarIsNull(XMLNode) then
However, in your case, the problem is little more complicated. The selectSingleNode
method returns always a variant of type varDispatch
whose actual data pointer points to a found XML DOM node, or to nil
in case no such node is found. In Delphi (language in which Inno Setup Pascal Script is written) there is the VarIsClear
function which covers also such situation. Unfortunately, it is not published in Inno Setup. You can however test this case with a statement like this:
if (IDispatch(XMLNode) = nil) then
That will get the data from the returned varDispatch
variant and those data test for nil
.
Martijn Laan added the VarIsClear
function to Unicode version of Inno Setup in this commit
, so since Inno Setup 5.5.6 you can use VarIsClear
instead of the above hack.