[fpc-pascal] Re: Variant vs Pointer

Marcos Douglas md at delfire.net
Sat Mar 3 16:40:46 CET 2012


On Sat, Mar 3, 2012 at 11:52 AM, Ludo Brands <ludo.brands at free.fr> wrote:
>>
>> Think in my class like a Business Object.
>> The struct is very similar with TParams it has many TParam. The data,
>> in a TParam, is save in a Variant type.
>> I need something like:
>> u := TmyBO.Create;  // the name does matter
>> u.Attr['name'].Value := 'Marcos';  // an instance is created and the
>> name is 'name' and the type is string
>>
>> The attributes are created on demand and the data is saved into a
>> Variant, like TParam.
>> If I do not use a Variant, I need to create one class to each type
>> that I will use, right?
>>
>
> 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?

>> 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?

Marcos Douglas



More information about the fpc-pascal mailing list