I have a class defined as:
TfraFrame = class(TFrame);
then I have several subclasses all inherting from this, such as:
TfraUsers = class(TfraFrame);
TfraGroups = class(TfraFrame);
TfraMenus = class(TfraFrame);
In my main form i have declared variables as:
var
fraUsers: TfraUsers;
fraGroups: TfraGroups;
fraMenus: TfraMenus;
Now my question is, I would like to have one single function to control the generation of the instances of each class. There should only be once instance of each class, but i only want to create the instances if the user requires them.
I would like to pass the variable like this:
procedure ShowFrame(Frame: TfraFrame)
begin
if Frame = nil then
begin
Frame := TfraFrame.Create(self);
Frame.Init(Panel1);
end;
Frame.Show;
end;
and call it like this;
ShowFrame(fraUsers);
I was expecting it to create a instance of TfraUsers
(because that is what fraUsers
is declared as), however, i suspect it may be creating an instance of fraFrame
.
Is there a way to create an instance of the type that the variable was declared as?