Показать сообщение отдельно
  #1  
Старый 21.12.2010, 12:55
praeeo praeeo вне форума
Прохожий
 
Регистрация: 08.03.2010
Сообщения: 9
Репутация: 10
По умолчанию Приведение типов с одинаковыми свойствами

Приветствую!
Что-то не возьму в толк, как сделать "красиво":
Есть два типа объектов с одинаковыми свойствами, объекты заносятся в 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: Пользуемся тегами, иначе последуют санкции!
Ответить с цитированием