VT_DECIMAL and Delphi 5

Anybody got a routine to convert the Variant when it is VT_DECIMAL into an Integer or Float or whatever - in Delphi 5 please.

The format is :-

    packed record
    wReserved : Word;  (* contains VT_DECIMAL *)
    scale : Byte;
    sign : Byte;
    data : packed array[1..12] of Byte;
    end;

(or anything equivalent)
LVL 27
BigRatAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ziolkoCommented:
you can try:
VarAsType(...., varDouble);

or

StrToFloatDef(VarToStr(...), default_value_if_conversio_fails)

ziolko.
0
diniludCommented:
Uses ComObj;

Const VT_DECIMAL=$000E;

procedure TForm1.Button1Click(Sender: TObject);
var V1: Variant;
    i:Double;
begin
  V1 := VarAsType(10.9,VT_DECIMAL);
  i:=V1;
  ShowMessage(FloatToStr(i));
end;
0
BigRatAuthor Commented:
Neither of these two responses were really what I was looking for.
My problem is an Oracle Database returning via ADO Decimal types.
The first suggestion by ziolko works of course, but what I'd really like to know is how to interpret the bytes in the decimal structure. In that way I can determine whether the value is an integer, and therefore convert to int type, or a fraction, in which case I'd convert to real. And I'd like to do that quickly without a sort of "trial and error" via the variant conversion routines. My interpreter, which supports COM, has only two numeric types - namely integer and real.
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

ziolkoCommented:
so you want to fill this structure
 TVTDecial = packed record
    wReserved : Word;  (* contains VT_DECIMAL *)
    scale : Byte;
    sign : Byte;
    data : packed array[1..12] of Byte;
    end;

?
if so then... it's a wild guess and I haven't tried it but you can try:

Move(TVarData(vtdecimal_variant).RawData, record, SizeOf(record));
or
Move(TVarData(vtdecimal_variant).VPointer, record, SizeOf(record));

ziolko.
0
BigRatAuthor Commented:
>>so you want to fill this structure

No, given the structure filled with a valid decimal number, what is the procedure for decoding it into an integer or a real? That is why I asked for a routine to process the structure. I am NOT interested in converting it into another Variant type.
0
ziolkoCommented:
ok, in this case I'm no-good.
sorry:/

ziolko.
0
BigRatAuthor Commented:
I'm not sure whether this link will work here :-

http://www.koders.com/cpp/fid6B109A4BFCD10B59E8ECECBBDE9A854AA0F0E006.aspx?s=decimal+microsoft

but the Microsoft file decimal.cpp at that web site contains the full code to decode/encode the decimal type into all other automation types.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.