[fpc-pascal] Re: Variant vs Pointer

Ludo Brands ludo.brands at free.fr
Sat Mar 3 17:20:43 CET 2012

> > Or define an internal storage format and convert the 
> different types 
> > to that format. That is also what variants are doing. The 
> difference 
> > is that variants have pre-defined assignment routines and 
> conversions 
> > between the different variant types which don't always fit what you 
> > want (date formats, decimal points, precision, characters 
> set, etc.). 
> > Assign fe. 1.2 to a variant and it will store it as a 
> double while you 
> > perhaps meant a 32 digit precision numeric value.
> I'm thinking to use JSON (TJSONData and subclasses) or at 
> least the same idea. Could you give an example to use a 
> internal storage format? Do you talk about Pointer and conversions?

When you are thinking of using JSON you can use AnsiString as the internal
format eventually adding a datatype tag to avoid conversion data loss as
much as possible.
I have never used TJSONData before but used a homebrewn json implementation
to transfer arbitrary database data. 

> >> If Variant is so bad, why TParam is implemented using it?
> >>
> >
> > That is a very good question. Delphi compatibility is probably the 
> > answer.
> >
> > Just look at the VarFmtBCD custom variant format created to fit the 
> > higher precision numeric data types and all the 
> difficulties to get it 
> > right.
> >
> > Ludo
> Well, TParams in Delphi works fine.
> My new class will works with DBMS data format (integer, 
> varchar, etc) very similar with TParams (I inherited of 
> TParams, at the moment) with more functionalities.
> The TParams class, AFAIK, should work well with DBMS data 
> format, don't?

Again, the higher precision numeric and decimal datatypes as used in fe.
Oracle are poorly supported with variants. If higher precision numerics,
date/time formats, decimal points and other locale related conversions
aren't an issue for you, and if you don't want strict compile time type
checking, please do use variants.


More information about the fpc-pascal mailing list