[fpc-pascal] question with interfaces, hooks

Sven Barth pascaldragon at googlemail.com
Wed Jul 15 08:05:27 CEST 2015


Am 15.07.2015 06:07 schrieb "David Emerson" <dle3ab at angelbase.com>:
[snip]
> constructor t_fancy_class.create;
>   begin
>     inherited;
>     f_hook := t_foo_base.create;
>   end;
>
> destructor t_fancy_class.destroy;
>   begin
>     t_foo_base(f_hook).free;
>     inherited;
>   end;
[snip]

Not related to your problem, but important nevertheless: you don't need to
free interface variables. They are reference counted an freed automatically
at least if you don't mix a class reference (in your case to t_foo_base)
and interface reference (in your case i_foo) which you shouldn't do anyway
(and which you aren't doing in your example).

I haven't work with delegation much, but you could try to do "(fc as
i_foo).foo;". Also you might want to take a look at TAggregatedObject.

Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20150715/d1a941ab/attachment.html>


More information about the fpc-pascal mailing list