[fpc-pascal] Extended, Currency and TDateTime memory layout

Zaher Dirkey parmaja at gmail.com
Sat Aug 7 22:44:38 CEST 2010


On Sat, Aug 7, 2010 at 9:56 PM, Felipe Monteiro de Carvalho <
felipemonteiro.carvalho at gmail.com> wrote:

> > A currency is a Int64, which is the currency amount multiplied by 10000.
>
> Well, apparently Delphi 6 RTTI thinks that it is a float. Check this code:
>
> 471               else if ElmTypeInfo.Kind in [tkFloat] then begin
> 472                 case TypeData.FloatType of
> 473                   ftSingle: Stream.Write(DynArray^, ArrayLength *
> SizeOf(Single));
> 474                   ftDouble: Stream.Write(DynArray^, ArrayLength *
> SizeOf(Double));
> 475                   ftComp: Stream.Write(DynArray^, ArrayLength *
> SizeOf(Comp));
> 476                   ftCurr: Stream.Write(DynArray^, ArrayLength *
> SizeOf(Currency));
> 477                   ftExtended: Stream.Write(DynArray^, ArrayLength *
> SizeOF(Extended));
> 478                 end;
>

A Currency is a Int64 not float, if you assign currency to float variable
(double/extended) and return back to currency variable, you will not get the
same value.
Typecast the currency as Int64, assign it to int64 variable and vise versa
you will not lose any thing.

Best regards
-- 
Zaher Dirkey
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20100807/bae4ff11/attachment.html>


More information about the fpc-pascal mailing list