On Tue, 19 Sep 2006, Cesar Romero wrote:


I have a question on the example below.

Why don't you use RTTI to define the properties ?
If you make the properties published, you don't need the AfterConstruction method. It won't work for all types, but most will do just fine.
RTTI could be used to get properties values, but as you mention is limited, using in this way I can expand as necessary. Look that the fields are custom types (IStringType, IDateType, IBlobType, etc), in AfterConstruction I call AddMember to create a instance of Fields.

TObjectType mantain a list of members (TStringHash), used for integration with other framewords (OPF and MVP).

var
 I: Integer;
 LPerson: IPerson
begin
LPerson:= TPerson.Create;
LPerson.Member['Name'].Value:= 'Cesar'

You can do this with RTTI ?


or

for I:= to LPerson.Count -1 do
begin
 if LPerson[I].State.Modified then
   ....
 end;

Same here ?


I have used RTTI in DePO, but was too much limited.

Both InstantObjects and ECO use RTTI. I don't think that qualifies as 'limited' 
:)
TiOPF also, as far as I know.

RTTI is only limited for certain special types, but for 99,99% of all cases
it is more than sufficient.

You are duplicating code, plus it is error-prone: if you forget or mistype
an AddMember in the AfterConstruction, the properties are not streamed properly. This cannot happen with RTTI.

Why not use a dual approach ? Use RTTI where appropriate, and use the manual
approach where RTTI is not possible ?

Michael.

_________________________________________________________________
    To unsubscribe: mail [EMAIL PROTECTED] with
               "unsubscribe" as the Subject
  archives at http://www.lazarus.freepascal.org/mailarchives

Reply via email to