You could declare TSuperhero = Class(TComponent)
.
A TComponent
ancestor has the ability to own and manage other components
Also make sure that your Constructor
is public if you want it visible to other units.
i.e.:
public
constructor Create(AOwner: TComponent); override;
...
constructor TSuperhero.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
// TSuperhero.Self now owns MyCon and responsible for freeing it
MyCon := TADOConnection.Create(Self);
end;
If Superhero
is needed across the application, I would instantiate TSuperhero
like:
Superhero := TSuperhero.Create(Application);
And let the Application
be the owner of Superhero
also responsible for freeing it.
Just to add to my answer, Your class TSuperhero
usage is very much like a TDataModule
(TComponent
), so maybe you should really use a centralized TDataModule
- drop a TADOConnection
on it, and so on, and use that instance across your application.