Could not convert variant of type (Null) into type (OleStr)

后端 未结 4 1229
离开以前
离开以前 2021-02-09 15:14

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

4条回答
  •  情深已故
    2021-02-09 15:28

    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)]));
    

提交回复
热议问题