[fpc-pascal] Quick Modern Object Pascal Introduction, for Programmers

Michalis Kamburelis michalis.kambi at gmail.com
Tue Jun 21 09:14:40 CEST 2016


2016-06-20 14:30 GMT+02:00 Marcos Douglas <md at delfire.net>:
> Don't agree with "Ugly (COM) interfaces". Yeah, _AddRef, _Release,
> QueryInterface is ugly implementation but reference-counting mechanism
> is nice.
>

Reference-counting is a useful concept, but "entangling" it with
interfaces is somewhat ugly IMHO. Those two concepts, and needs,
should be unrelated language features in my opinion:

- you use interfaces when you want to cast a class to multiple
possible interfaces,
- you use reference-counting to get automatic memory management (to
some extent, e.g. beware of cycles).

Both of these are useful, but forcing them together seems ugly. And it
causes actual problems:

- Various classes, using standard TComponent, have to "hack around"
reference counting by proving _AddRef implementations that do nothing,
- Even with hack above, you need to be extra careful about interface
temporary variables (you cannot free the class instance, if some
temporary interface variable may refer to it).

Regards,
Michalis



More information about the fpc-pascal mailing list