#1 Yesterday 11:18:13

koraycayiroglu
Member
Registered: 2017-02-03
Posts: 90

VariantToInteger does not convert OleVariant to integer

Hi,

I am working with xml nodes and when assigning some values from xml to record i use mormot's functions obviously but it seems variant conversions does not work with OleStr or OleVariant types. Value is something like '688' and there is no case for OleStr so it will use SetVarDataUnRefSimpleValue which returns false.

This is not a major problem or anything, it just catch my eye and want you to know.

Best regards.

Last edited by koraycayiroglu (Yesterday 11:19:24)

Offline

#2 Yesterday 12:14:42

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 15,492
Website

Re: VariantToInteger does not convert OleVariant to integer

SetVariantUnRefSimpleValue() only supports "simple" types, as documented and stated by its name.

WideString / BSTR are properly handled as varOleStr in mORMot code but not by this SetVariantUnRefSimpleValue() function for sure.

OleVariant could mean anything.
What does OleVariant mean  in your case?
Where is SetVariantUnRefSimpleValue() called in your code?

Offline

#3 Today 08:25:34

koraycayiroglu
Member
Registered: 2017-02-03
Posts: 90

Re: VariantToInteger does not convert OleVariant to integer

it's very simple.

procedure Test(const Node: IXMLNode);
begin
  if not VarIsEmptyOrNull(Node.ChildValues['RecID']) then self.fRecID := VariantToInteger(Node.ChildValues['RecID']);
end;

Using ChildValues returns a OleVariant type and when i send that value to VariantToInteger, V's VType is 8 which is varOleStr. there is no case for varOleStr so it falls into else case and uses SetVarDataUnRefSimpleValue and fails.

Offline

#4 Today 13:31:10

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 15,492
Website

Re: VariantToInteger does not convert OleVariant to integer

It works just as documented: VariantToInteger() expect true numerical Variant and won't convert any string.
Here the input is a string, not a numerical value. So the function fails.

But anyway, which VariantToInteger() version are you using? there is no such function with a single parameter in mORMot.

The easiest may be to change your code e.g. to use regular RTL function, e.g. StringToInteger().

Or you can try the new AnyVariantToInteger() method:
https://github.com/synopse/mORMot2/commit/06d6452bc

Offline

Board footer

Powered by FluxBB