I have a main class and several inherited classes that implement a method with the same name, like this:
MainClass = class(TImage)
//main class methods...
end;
MyClass1 = class(MainClass)
procedure DoSomething;
end;
MyClass2 = class(MainClass)
procedure DoSomething;
end;
MyClass3 = class(MainClass)
procedure DoSomething;
end;
I also have a TList containing pointers to object instances (of several classes).
If I want to call the right DoSomething procedure for each class, do I use the following?
if TList[i] is MyClass1 then
MyClass1(TList[i]).DoSomething
else if TList[i] is MyClass2 then
MyClass2(TList[i]).DoSomething
else if TList[i] is MyClass3 then
MyClass3(TList[i]).DoSomething
Is there some casting method that allows me to do this in a few lines of code?