could not convert variant of type

При фильтрации появляется Ошибка
«Project Project1.exe raised exception class EVariantTypeCastError with message ‘Could not convert variant of type (Null) into type (String)’. Process stopped. Use Step or Run to continue.»

procedure TfDM.SharedFilterRecord(DataSet: TDataSet; var Accept: Boolean);

c:=Copy(DataSet[‘Ôàìèëèÿ’], 1, Length(edt1)); Лучший ответ

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.

The function is then executed at FormCreate:

Thank you so much for your help.

4 Answers 4

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.

To avoid the error message do

NullStrictConvert := false; // 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 :

How can I handle this type of error, Could not convert variant of type (string) to type (double)?
Are there other method that can be used to access data? Earlier version had a strings[] method
LineItems.Add(‘User Count: ‘+ Values[ARowInfo.RecordIndex, tvProductsNumberOfUsers.Index]);

Hi Ron!
The information provided is not enough to diagnose your problem for certain, sorry. Please specify the Grid and Delphi IDE versions you are using. Please also describe your task in detail or attach a small sample project which demonstrates your problem. For now, I assume that you try to convert the value obtained via the DataController.Values method into a string. If so, the problem is that DataController.Values returns variant type. Try to correct your code as follows:
.
LineItems.Add(‘User Count: ‘+ VarToStr(Values[ARowInfo.RecordIndex, tvProductsNumberOfUsers.Index]));
I hope this will help you.
Thanks,
Nicolas.

Your solution worked fine. But I asked another question also. Is there other methods to access the data associated with a grid cell other than values there use to be a strings property.

Оцените статью