BigRat
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)
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)
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;
Const VT_DECIMAL=$000E;
procedure TForm1.Button1Click(Sender
var V1: Variant;
i:Double;
begin
V1 := VarAsType(10.9,VT_DECIMAL)
i:=V1;
ShowMessage(FloatToStr(i))
end;
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.
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_va riant).Raw Data, record, SizeOf(record));
or
Move(TVarData(vtdecimal_va riant).VPo inter, record, SizeOf(record));
ziolko.
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_va
or
Move(TVarData(vtdecimal_va
ziolko.
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.
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.
sorry:/
ziolko.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
VarAsType(...., varDouble);
or
StrToFloatDef(VarToStr(...
ziolko.