If I implement an interface on a form such as TMyForm = class(TForm, IMyInterface)
, will the object free itself when there are no more interface references to it? It seems not to, although I couldn't work out how TForm is reference counted (if at all). I'm concerned about the form getting freed when an interface reference goes out of scope, but this does not seem to happen.
I guess there are two parts to the question, firstly whether a form might get unexpectedly freed (the real question), and secondly how forms are reference counted.
TComponent
disables reference counting on itself, but will perform reference counting on itsVCLCOMObject
property, if assigned. – IgnaciaignacioTForm
class). If adding of that interface is dangerous somehow, and if that adds a reference counting to the form. – OntologismTForm
will not add a reference count to theTForm
. The compiler will still call_AddRef()
and_Release()
on interace pointers but they will be no-ops because ofTComponent
. – Ignaciaignacio