[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 550
  • Last Modified:

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)
0
BigRat
Asked:
BigRat
  • 3
  • 3
1 Solution
 
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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
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

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now