Hello
,
I Just wanted to ask how i could realize the following:
Superclass:
SuperC = class(TObject)
SubClass
MyForm = class(TForm) --> Should inherit from the "SuperC"
I have several forms, which share some properties. Therefore I wanted to create a superclass that initializes the variables of the shapes. Is it possible to do this with inheritance ? Since the form can't inherit from TForm and another class I don't know exactly which solution would be best here. Of course I could just manually assign the variables to the class each time, but this would not be such a nice solution in my eyes.
Maybe some tips from professionals?
########################################################################
Edit:
I realized that a class can derive from TForm even if it has no form itself. So now my "Data" class can initialize all forms. Should hopefully not give any peroblems later (haven't tested everything). If someone has a better solution I would be very happy if you could share it here.
Superclass:
TCars = class(TForm) --> Does not have a Form
TLocations = (LocGermany, LocRussia);
SubClass
TMyCar= class(TCars )
TMyTruck= class(TCars )
TMyMotorcycle= class(TCars )
Array of Components (Example)
Traffic : Array of TCars;
Traffic[1] := TMyCar.Create
Traffic[2] := TMyTruck.Create
Traffic[3] := TMyMotorcycle.Create
Traffic[1].SetGoal := LocGermany
Traffic[1].SetStart := LocRussia
Traffic[1].Drive();
Thanks