erp入库老是显示could not convert variant of type(olestr to double) into type (double)是怎么回事

delphi - Could not convert variant of type (Null) into type (OleStr) - Stack Overflow
to customize your list.
Join the Stack Overflow Community
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.
J it only takes a minute:
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 computers generate the error message.
function GetWMIstringSW(const WMIClass, WMIProperty:string):
wbemFlagForwardOnly = $;
FWbemObjectSet: OLEV
FWbemObject
Result:='';
FWbemObjectSet:= FWMIService.ExecQuery(Format('Select %s from %s',[WMIProperty, WMIClass]),'WQL',wbemFlagForwardOnly);
:= IUnknown(FWbemObjectSet._NewEnum) as IEnumV
while oEnum.Next(1, FWbemObject, iValue) = 0 do
if not VarIsNull(FWbemObject.Properties_.Item(WMIProperty).Value) then
Result:=FWbemObject.Properties_.Item(WMIProperty).V
LNode := ClientForm.TreeView1.Items.AddChild(Node, Format('%s',[String(FWbemObject.Name)]));
LNode2 := ClientForm.TreeView1.Items.AddChild(LNode, Format('%s',[String(FWbemObject.Version)]));
FWbemObject:=U
The function is then executed at FormCreate:
GETWMIstringSW('Win32_Product','Name');
Thank you so much for your help.
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
function or just use the
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)]));
113k11253398
If you want to null variants to be automatically converted to empty strings, 0 integers, or false booleans, set NullStrictConvert (unit System.Variants) to true.
4,370113067
To avoid the error message do
NullStrictConvert := // avoid NULL OLE conversion error
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]) );
Your Answer
Sign up or
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Post as a guest
By posting your answer, you agree to the
Not the answer you're looking for?
Browse other questions tagged
The week's top questions and answers
Important community announcements
Questions that need answers
By subscribing, you agree to the
Stack Overflow works best with JavaScript enabled的海词问答和网友补充:
相关词典网站:delphi could not convert variant of type (null) into type (olestr)解决方法
&来源:读书人网&【读书人网():综合教育门户网站】
delphi could not convert variant of type (null) into type (olestr)procedure TForm3.DBEdit1Change(Se
delphi could not convert variant of type (null) into type (olestr)procedure&TForm3.DBEdit1Change(Sender:&TObject);&//onchange事件vari:s:xcom:beginfor&i&:=&2&to&20&dobegins:='edit'+inttostr(i);xcom:=findcomponent(s);if&xcom&&nil&thenbeginTedit(xcom).Text:=ADOquery1.Fields[i-2].V&//break&按了之后这一条被选中了。错了么?procedure&TForm3.FormShow(Sender:&TObject);beginADOConnection1.Connected:=&//连接,设置。ADOConnection1.Connected:=ADOQuery1.Connection:=adoconnection1;ADOQuery1.SQL.CADOQuery1.CADOQuery1.SQL.Text:='select&CustomerID,pyCode,CustomerName,ProvinceID,CityID,Address,Zip,Phone,Fax,Email,HomePage,Industry,Type,Source,Status,Revenue,employees,owner,StockNo,Notes&from&customers';ADOQuery1.ODataSource1.DataSet:=adoquery1;ADOtable1.CADOtable1.Connection:=ADOConnection1;&//连接adotable后做的事情ADOtable1.tablename:='customers';ADOtable1.Odbnavigator1.DataSource:=DataSource1;dbgrid1.DataSource:=DataSource1;edit1.Text:='';f();&//外观设置的函数调用procedure&TForm3.ToolButton5Click(Sender:&TObject);&//刷新按钮beginadoquery1.Cadoquery1.Of();我能写的都写了,但是刷新按钮还是错,错误提示如题。我什么都不做,运行先按刷新还是出现同样的错误。我不知道我sql语句哪里被修改了?
[解决办法]Tedit(xcom).Text:=ADOquery1.Fields[i-2].V&//break&按了之后这一条被选中了。错了么?Tedit(xcom).Text:=ADOquery1.Fields[i-2].//用这个确保是文本你的错误代码没有贴出来,你的F函数有问题。}

我要回帖

更多关于 variant t double 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信