There is another great limitation of your suggested solution.
The offsets for the objects are bound at compile time.
While the record solution allows the offsets to be determined at run time.
Making the record solution a more flexible solution.
In other words objects need to specify their ancestor at compile time
creating the inflexibility.
The make things even worse. For every possibility a new object declaration
would be needed and finally it would be an unacceptable solution because
this would probably add runtime type information to the objects thereby
adding unwanted fields.
However there might be a different solution which might still be
interesting:
1. Non-inherited objects.
2. Maybe empty objects ?
I shall investigate those later on.
Bye,
Skybuck.
----- Original Message -----
From: "Daniël Mantione" <[EMAIL PROTECTED]>
To: "FPC-Pascal users discussions" <fpc-pascal@lists.freepascal.org>
Sent: Saturday, February 16, 2008 5:24 PM
Subject: Re: [fpc-pascal] Empty record inside another record ?
Op Fri, 15 Feb 2008, schreef Skybuck Flying:
To me it seems like some kind of trick, to extend a record at runtime.
The empty record field, functions as a sort of offset/label/pointer if you
will to the new fields that will will be extended to the record by simply
allocating more memory then the size of the record.
Then this "label"/"field" can be used as a sort of offset, by typecasting
it
to some extension record type.
Could be pretty handy, quite impressive trick.
However, is it safe to use ?
Empty records are valid Pascal.
I cannot find anything in the documentation about this ?
Nothing in the documentation says it is forbidden either. The reason
it is not explicetely mentioned is because there exists a
much better method, objects:
type base_structure=object
field1:byte;
end;
extended_structure=object(base_structure)
field2:byte;
end;
Daniël
--------------------------------------------------------------------------------
_______________________________________________
fpc-pascal maillist - fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
_______________________________________________
fpc-pascal maillist - fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal