I need a base class like TInterfacedObject
but without reference counting (so a kind of TNonRefCountedInterfacedObject
).
This actually is the nth time I need such a class and somehow I always end up writing (read: copy and pasting) my own again and again. I cannot believe that there is no "official" base class I can use.
Is there a base class somewhere in the RTL implementing IInterface
but without reference counting which I can derive my classes from?
You might consider TInterfacedPersistent. If you don't override GetOwner it does no ref-counting.
In the unit Generics.Defaults there is a class TSingletonImplementation defined. Available in Delphi 2009 and above.
I don't know of any out-of-the-box base class, so I wrote my own (like you). Just put it in a common utils unit and you are done.
I did this. It can be used in place of TInterfacedObject with or without reference counting. It also has a name property - very useful when debugging.
There is no such class, but you can easily write your own, as others have shown. I do, however, wonder why you would need it. In my experience, there is seldom a real need for such a class, even if you want to mix object and interface references.
Also note that when you use such a class, you'll still have to take care of setting any interface references you have to such an object to nil before they leave scope and before you free the object. Otherwise you might get the situation the runtime tries to call _Release on a freed object, and that tends to cause an invalid pointer exception.
IOW, I would advise against using such a class at all.