How to check if an object is NULL in Inno Setup Pascal Script?

I am writing a pascal function using the Inno installation studio, which checks if an object is null and does something

So far, I:

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 an invalid variant operation error.

How to check if an object is null in Inno Setup Pascal Script code?

+6
source share
1 answer

To verify that Variant NULL uses VarIsNull :

 if VarIsNull(XMLNode) then 

However, in your case the problem is a little more complicated. The selectSingleNode method always returns a variant of the varDispatch type varDispatch actual data pointer points to the found XML DOM node or to nil if such a node is not found. Delphi (the language Inno Setup Pascal Script is written) has a VarIsClear function that also covers this situation. Unfortunately, it is not published in Inno Setup. However, you can verify this case with the following statement:

 if (IDispatch(XMLNode) = nil) then 

This will get the data from the returned varDispatch variant and that data for nil .


Martijn Laan added the VarIsClear function to the Unicode version of Inno Setup in this commit , since Inno Setup 5.5.6 you can use VarIsClear instead of the aforementioned hack.

+10
source

Source: https://habr.com/ru/post/977712/


All Articles