[fpc-pascal] Managed record questions
Michael Van Canneyt
michael at freepascal.org
Fri Mar 9 09:55:46 CET 2018
On Fri, 9 Mar 2018, Ryan Joseph wrote:
>> On Mar 9, 2018, at 1:53 PM, Sven Barth via fpc-pascal <fpc-pascal at lists.freepascal.org> wrote:
>> They are broken, deprecated and essentially dead in Delphi, but in FPC we've always cared for them as well.
>> Overloads and generics are already supported and support for helpers could be easily added. Only major feature missing compared to classes is the support for extensive RTTI.
> Out of curiosity I did some quick tests and learned a few things:
> 1) Interfaces don’t work as far as I can tell (too bad)
> 2) The constructor/destructor situation is pretty messy (deref using ^ could be omitted like classes probably) but that’s how they were in the past.
Hence my proposal to 'clean this up'.
> 3) I suppose it never existed but “override” missing is pretty strange. Historical I guess.
You don't need "overrid"e for objects, it is automatical.
> 4) Move() on an object copies memory like a record (as a record does, so this is good). Does that mean they laid out in memory just like records?
Yes, although I believe there is a hidden VMT field.
> So why do we have advanced records then if objects do more than records?
> The overhead of a virtual method table? Records have a better/cleaner syntax for operator overloads than even classes but what else?
Simple: Delphi compatibility.
You can probably find some of my cries of despair on the mailing lists,
lamenting the fact that they decided to invent something new when they had
it all along since many decades :(
> Unlike C++ the object’s destructor was not called when it went out of scope but if it did that they would be an interesting replacement
> for classes in some cases. The compiler knows how to cleanup stack variables but does it call any virtual method on objects in this situation?
I do not think so.
More information about the fpc-pascal