I was creating a "object holder" class that would destroy it's holded
object after a certain time had been reached.
Frantically I go around and create the basic object and it's holder...
But to keep things simple, I expose the use of the object through an
interface and a singleton construction method.
Things work out just fine, and I realize I could use this code in a
more generic sence, so I try to seperate the holder object from the
TObjectHolder = class(TTimer)
function GetIntf: IInterface;
procedure OnCustomTimer(Sender: TObject);
constructor Create(AInterfacedClass: TInterfacedClass);
destructor Destroy; override;
property Intf: IInterface read GetIntf;
function TObjectHolder.GetIntf: IInterface;
Enabled := False;
if not Assigned(FIntf) then begin
FIntf := FIntfClass.Create; // For some reason this doesn't work!
//FIntf := TMyInterfacedClass.Create; // This would have worked
though. but not what I needed ;)
Result := FIntf;
Enabled := True;
Personally I thought this "should" have worked, as it does with
ordinary classes descending from TObject. I have done this many times
before, and was obviously stumped as to why my create constructor of
type FIntfClass wasn't being called.
I figured I'd be smart, and create this holder... The idea of course
is that some big objects would be called for every now and again...
and instead of creating the instance every time, the object would live
on for a certain period of time before destroying it's holded object
if it wasn't referenced no more (but by himself)...
Every time a reference is needed, the timer is reset, and the object
lives on for another period...
I hope someone can shed some light on what I can do to make this
Thanks in advance for any advise :D