My top level class is TBaseDB
, which has a descendant TCommonDB
(, and TCommonDB
will have multiple descendants, like TProdDB
and TDevDB
).
Let's create a function in each class definition, called Test1
. For now, all it does is a ShowMessage('Some literal')
just to show me what code is being executed.
I don't know the class type until runtime. I want to have common code, but different behavior.
What I want is something like this:
var
MyObj: TBaseDB;
begin
//pseudo-code...
if RadioButton1.Checked then
MyObj := TBaseDB.Create
else
MyObj := TCommonDB.create;
MyObj.Test1;
end;
I can't seem to get this to work, and I imagine it is in my class definition. How should Test1
be defined so that:
- I can declare my variable as
TBaseDB
, - the created class can be either
TBaseDB
orTCommonDB
, and - the proper
Test
procedure will be called depending on the instance being aTBaseDB
orTCommonDB
?