I have a dictionary with multiple types of TObject
(for example, TEdit
, TComboBox
, TButton
, etc).
I want to loop through each of them, and do something with the casted version of each control, but I don't want to check the type and cast for each one, because if I have 10 different controls, I have to do 10 different if
checks. Here's my code right now:
for LInputItem in FInputFactory do
begin
if(LInputItem.Value.ClassName = 'TEdit') then begin
(TEdit(LInputItem.Value)).Whatever;
end else if LInputItem.Value.ClassName = 'TComboBox' then begin
(TComboBox(LInputItem.Value)).Whatever;
end;
end;
And that's just 2 types.