For a simple TInterfacedObject without reference counting, there is System.Generics.Defaults.TSingletonImplementation. But that is oddly named and hard to find, hence BatSoft.Classes.TInterfacedObject.


Sometimes I want interfaced objects to free when the RefCount is something other than 0, such as when writing factories that keep track of multitons.
This is simply a TInterfacedObject where the reference count has been offset. It may be a hack, but the logic is tight.


Enables adding interfaces to a class that is not a TInterfacedObject.

Did you ever have a class that you wanted to add an interface to, but couldn’t change the root class to TInterfacedObject, and didn’t want to explicitly implement the IInterface methods? Well, here is your solution.

Add the following to your class declaration:

  fIntf: IInterface;
  property Intf: IInterface read fIntf implements IInterface;

Add the following to the constructor:

fIntf := TRefCountMyOwner.Create(Self);

Now you’ve added reference counting to your class, so you can add interfaces as you like:

TMyClass = class(TParentClass, IMyInterface)


Generic types are great. But they’re not runtime types, so you can’t query a TList<XYZ> object to find out what type XYZ is.

RegisteredLists enables the registration of container classes and their related element types. Later, when you have a collection object, you can ask RegisteredLists to find out what element type it holds. This is used in other BatSoft units.


Think of this as a binary sorted TList<>. This is useful for indexing.

It’s actually a wrapper for TList<> and many methods simply pass through to the internal TList<> object. But this class adds binary sorting and associated limitations.

For example; you can’t insert elements, only add them. TBinaryList<> will put the new items into their proper places.


This is a place to put generic and useful routines for attribute arrays. It saves re-writing the same old loops to search for specific attributes.

Note: The parameter FoundAttribute is actually an output parameter that returns the attribute when it’s found.

procedure ChangeClass()

Change the class of an object.

This comes in handy when you want to extend, for example, controls in forms. Consider this:

You want to add functionality to a control that is only used in one form. (I do this when testing a control’s functionality.) So, you make a descendant class where you override a method (ex. Paint). Normally, to see your control on the form in design time, you would register the new component in a package and install that package.

  TForm2 = class(TForm)
    Label1: TLabel;
    procedure FormCreate(Sender: TObject);

  TTestLabel = class(TLabel)
    procedure Paint; override;


{ TForm2 }

procedure TForm2.FormCreate(Sender: TObject);
  ChangeClass(Label1, TTestLabel); // <-  Change Label1 from TLabel to TTestLabel

{ TTestLabel }

procedure TTestLabel.Paint;
  //  Test code here

With this procedure you simply change the component’s class to your descendant class at runtime. One line! Simple.

Note: This procedure contains safeguards to reduce the risk of bugs, but please make certain you know what you’re doing.