parentobject (unit): Type TParentObject = class(TObject) Type TParentObjectClass = class of TParentObject; Object1 (unit): type TObject1 = class(TParentObject) public procedure DoSomething; Object2 (unit): type TObject2 = class(TParentObject) public procedure DoSomething; etc for a number of different types of objectsNow I can handle these objects of course like
var Object1 := TObject1.Create
but I want to have this generic for all objects.
Class referencing is supposed to allow for that,
and the following does indeed work :
var MyObject := TParentObjectClass.Create; (MyObject as TObject1).DoSomething; (MyObject as TObject2).DoSomething; etcWhat I want though is even more generic handling as in:
var MyObject := TParentObjectClass.Create; and suppose I have all the different object classtypes stored in an ObjectClassArray : array of TParentObjectClass then this should work (MyObject as ObjectClassArray[i]).DoSomething;except it doesn't
However if I check certain values of ObjectClassArray then these checks are true
For instance if the first array entry refers to Object2 then
If ObjectClassArray = TObject2 then console.log('true'); logs true
Any ideas why I can't use the generic "(MyObject as ObjectClassArray[i]).DoSomething;" statement above
or an alternative method for what I want to achieve ?