Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Variant type VarDecimal not supported in Delphi XE?


This question is answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 2 - Last Post: Jan 13, 2015 7:21 AM Last Post By: Arthur Hoornweg
Arthur Hoornweg

Posts: 414
Registered: 6/2/98
Variant type VarDecimal not supported in Delphi XE?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 13, 2015 12:06 AM
Hello all,

I'm in the process of migrating an ADO based application to Firebird embedded. I am using ADO through an ODBC driver to access the database and that works fine, everything is very promising. However, some of the fields in my database are defined as Numeric (9,4) to mimick the Microsoft "smallmoney" type. This is basically a 4-byte currency.

When I query such fields, as in "SELECT MAX(myfield) from Mytable" , then ADO returns a field that contains a variant of type 14 (=VarDecimal). Much to my dismay, I cannot assign such a variant to a floating point value in Delphi XE.

I feel as if I'm being thrown back into the stone age. Surely other people must have noticed this ages ago. Is this a known issue in Delphi and is there a fix?
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Variant type VarDecimal not supported in Delphi XE?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 13, 2015 12:54 AM   in response to: Arthur Hoornweg in response to: Arthur Hoornweg
Arthur wrote:

Is this a known issue in Delphi

Yes:

support of variants of type 14 (varDecimal)
http://qc.embarcadero.com/wc/qcmain.aspx?d=3474

and is there a fix?

No. You will have to create your own function to extract the decimal value
from a Variant.

--
Remy Lebeau (TeamB)
Arthur Hoornweg

Posts: 414
Registered: 6/2/98
Re: Variant type VarDecimal not supported in Delphi XE?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 13, 2015 7:21 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:

No. You will have to create your own function to extract the decimal value
from a Variant.

OK. I just found a quick and dirty way to do it. Remember I'm just interested in the special case of DECIMAL(X,4) which I want to map to "CURRENCY".

First I found out the structure of a variant that contains a decimal number. That turned out to be simple.
Then I wrote a simple routine that converts such decimal-variants into currency-variants.
Finally I wrote a hook procedure (using the wonderful "DDETOURS" library) that hooks directly into the routine adoint.field20.get_value. In this hook I convert the variant before it reaches the application.

Of course this method is "dirty" but the advantage is that it is completely transparent to my existing application. As far as my application is concerned, Firebird now supports currencies through ADO.

Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02