I am using Delphi. I have a root class and many derived class from the root, the name of the class says TROOT, TA, TB, TC … In the code, I have some code to control the flow of the program by following code
var
obj :TROOT;
begin
if ((obj is TA) or (obj is TB) or (obj is TC) or (obj is TD)) then
begin
// some other codes here
end
end;
this code works good but then I extend my code so more subclasses are derived from TROOT and that swtich appears at more than one place in the program. Is there any way I can put the class type into a set or array and have some psudeo code like following so I don’t have to modify everywhere when the code is extended?
classarray = {TA, TB, TC, TD, TE, TF};
if (obj in classarray) then
begin
// put my code here
end
Thanks.
You can of course put the classes in an array. Declare the types like this:
Declare and populate the array:
Then you can test the contents of the array: