Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2011-10

cvarutil: convert variant array of bytes into ansistring ?

3 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

LacaK

Hi,
I am now working on fcl-db TBinaryField, which has Value: Variant property. As I understand documentation, this variant should be returned as variant array of bytes.

Later when are assigning values of fields into params also this variant array is copied (into TParam).

But when I want/need read parameter value as string (binary string) then "variant convert error" occurs.
It is because in cvarutil.inc in Function VariantToAnsiString(const VargSrc : TVarData) is not supported conversion from variant array into string.

So my question is if it is acceptable to add there support for converting byte array to string ?
Something like attached diff.

Please let me know, if this can be accepted/applied ? Thanks
-Laco.

Reply by email

Sergei Gorelkin
to LacaK

21.10.2011 13:47, LacaK пишет:

Show quoted text 15 lines
Hi, I am now working on fcl-db TBinaryField, which has Value: Variant property. As I understand documentation, this variant should be returned as variant array of bytes. Later when are assigning values of fields into params also this variant array is copied (into TParam). But when I want/need read parameter value as string (binary string) then "variant convert error" occurs. It is because in cvarutil.inc in Function VariantToAnsiString(const VargSrc : TVarData) is not supported conversion from variant array into string. So my question is if it is acceptable to add there support for converting byte array to string ? Something like attached diff. Please let me know, if this can be accepted/applied ?

It has to be done in a different and more complex way, by using VariantChangeTypeEx to convert the variant(array) to varOleString type, then converting latter to ansistring. This way, in Windows the job will be delegated to OS, which is Delphi compatible. For non-Windows, the relevant code ends up in VariantChangeTypeEx (varutils.inc). Also, you'll need to access the variant array with SafeArray* functions, and make checks that it is actually one-dimensional and its element type is eligible for conversion.

Sergei

Reply by email

LacaK
to LacaK: I am now working on fcl-db TBinaryField, which has Value: Variant property. As I…

Hi Sergei,
Thank you for your reply.
As it is out of my comfort zone, I leave it to up to you (if or when you implement this) TIA
-Laco.

Show quoted text 31 lines
It has to be done in a different and more complex way, by using VariantChangeTypeEx to convert the variant(array) to varOleString type, then converting latter to ansistring. This way, in Windows the job will be delegated to OS, which is Delphi compatible. For non-Windows, the relevant code ends up in VariantChangeTypeEx (varutils.inc). Also, you'll need to access the variant array with SafeArray* functions, and make checks that it is actually one-dimensional and its element type is eligible for conversion. Sergei Hi, I am now working on fcl-db TBinaryField, which has Value: Variant property. As I understand documentation, this variant should be returned as variant array of bytes. Later when are assigning values of fields into params also this variant array is copied (into TParam). But when I want/need read parameter value as string (binary string) then "variant convert error" occurs. It is because in cvarutil.inc in Function VariantToAnsiString(const VargSrc : TVarData) is not supported conversion from variant array into string. So my question is if it is acceptable to add there support for converting byte array to string ? Something like attached diff. Please let me know, if this can be accepted/applied ? Thanks -Laco.

Reply by email