Приветствую!
Что-то не возьму в толк, как сделать "красиво":
Есть два типа объектов с одинаковыми свойствами, объекты заносятся в TObjectList.
Вопрос - как мне сделать приведение типов, не дублируя код со свойствами и не используя явное приведение? Вот пример:
Код:
procedure TSettForm.SetProperty (Prop, Str: string);
var
bufbtnlist: TObjectList;
begin
if (bufbtnlist.Items[iindex-1] as TObject).ClassName = 'TBtnProp' then
with (bufbtnlist.Items[iindex-1] as TBtnProp) do
begin
if Prop = 'Hint' then Hint:= Str;
if Prop = 'LeftURL' then LeftURL:= Str;
if Prop = 'RightURL' then RightURL:= Str;
if Prop = 'LeftHotKeys' then LeftHotKeys:= Str;
if Prop = 'RightHotKeys' then RightHotKeys:= Str;
end;
if (bufbtnlist.Items[iindex-1] as TObject).ClassName = 'TMySpeedBtn' then
with (bufbtnlist.Items[iindex-1] as TMySpeedBtn) do
begin
if Prop = 'Hint' then Hint:= Str;
if Prop = 'LeftURL' then LeftURL:= Str;
if Prop = 'RightURL' then RightURL:= Str;
if Prop = 'LeftHotKeys' then LeftHotKeys:= Str;
if Prop = 'RightHotKeys' then RightHotKeys:= Str;
end;
end;
Admin: Пользуемся тегами, иначе последуют санкции!