Delphi: using BigInts from a database

I am using Delphi 7 with devart dbExpress to connect to SQLServer . The problem is that when I add the bigInt field to ClientQuery , it comes as TFMTBCDField .

And TFMTBCDField has no way to get a 64-bit value.

I can use Field.AsVariant or StrToInt64(Field.AsString) to select this 64-bit value.

Is there a better way to select / use this value?

+4
source share
4 answers

Maybe add manually to the TLargeIntField dataset, set its field name to the corresponding name and use this code:

 SomeInt64Value := (qryMyQuery.FieldByName('blahblah') as TLargeIntField).AsLargeInt; 

I donโ€™t remember exactly the types, but it worked this way in Delphi6.

+4
source

You can convert BCD to Variant, and not to int64 with VarFMTBcdCreate from the FMTBcd block.

Try the following:

 var value64 : int64; ... value64 := VarFMTBcdCreate(Field.Value); 
0
source

The data format for TFMTBCDField is the TBcd entry from the FMTBcd module. You can get this raw value by reading the properties of the Value or AsBCD .

Depending on what you need, a TBcd value may be sufficient. That is, you may not need to convert it to Int64 . The FMTBcd module provides functions for adding, subtracting, multiplying, and separating TBcd values.

The unit does not provide Int64 conversions. There are transformations Variant , string , Currency , Double and Integer . If we're going to write an Int64 transform, the Integer transform is probably a good place to start, so let's see how this is implemented:

 function BcdToInteger(const Bcd: TBcd; Truncate: Boolean = False): Integer; var ABcd: TBcd; begin if Truncate and (BcdScale(Bcd) > 0) then NormalizeBcd(Bcd, ABcd, Bcd.Precision, 0) else ABcd := Bcd; Result := StrToInt(BcdToStr(ABcd)); end; 

So, VCL itself does not provide a more direct way to convert TBcd to Integer than for passing a string . So it seems your idea to call StrToInt64 in the string version of the field is fine.

0
source

I no longer have Delphi 7, but, looking for help, I see that you can get Float (Double), for example:

 function GetFieldAsInt64(Field: TField): Int64; begin Result:= Int64(Round(Field.GetAsFloat)); end; 

And then call the function:

 var Value: Int64; begin Value:= GetFieldAsInt64(MyFMTBCDField); end; 
-1
source

All Articles