Do you know why the block of code bellow will negate the \"Could not convert variant of type (Null) into type (OleStr)\" on some computers, not all of them but 3 out of ten comp
You code fails when the value of a WMI property returns null. You can fix this, checking if the property has a null value before to cast or convert to an string. For this task you can use the VarIsNull function or just use the VarToStr method to safely convert variants to strings like so.
LNode := ClientForm.TreeView1.Items.AddChild(Node,
Format('%s',[VarToStr(FWbemObject.Name)]));
LNode2 := ClientForm.TreeView1.Items.AddChild(LNode,
Format('%s',[VarToStr(FWbemObject.Version)]));
Sometimes, the FWbemObject is not NULL but an exception is raise : "Can'nt convert an Array of Variant in OleStr "
As exemple : the BiosVersion (is an array) To solve it, try this :
for I := VarArrayLowBound(FWbemObject.BIOSVersion, 1) to VarArrayHighBound(FWbemObject.BIOSVersion, 1) do L.Add( VarToStr(FWbemObject.BIOSVersion[i]) );
Regards
Zerrouki
If you want to null variants to be automatically converted to empty strings, 0 integers, or false booleans, set NullStrictConvert
(unit System.Variants) to False
.
To avoid the error message do
NullStrictConvert := false; // avoid NULL OLE conversion error