Link to home
Start Free TrialLog in
Avatar of BigRat
BigRatFlag for France

asked on

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)
Avatar of Lukasz Zielinski
Lukasz Zielinski
Flag of Poland image

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

or

StrToFloatDef(VarToStr(...), default_value_if_conversio_fails)

ziolko.
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;
Avatar of BigRat

ASKER

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.
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.
Avatar of BigRat

ASKER

>>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.
ok, in this case I'm no-good.
sorry:/

ziolko.
ASKER CERTIFIED SOLUTION
Avatar of BigRat
BigRat
Flag of France image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial