Вниз
Скачать: CL | DM;

Делегирование реализации интерфейсов   Найти похожие ветки 

 
Priest ©   (2006-08-01 13:48) [0]

Есть класс, в котором реализуется интерфейс. В дргуом классе также необходимо реализовать тот же интерфейс, но непоторые свойства нужны publisher. Делаю так:

IMyInterface = interface(IInterface)
 ["{226F9C33-14C1-413F-A34D-EB37EBD354E9}"]
   function GetValue_: Integer;
   procedure SetValue_(const Value: Integer);
   property Value_: Integer read GetValue_ write SetValue_;
 end;

 TMyIntfImpl = class(TComponent, IMyInterface)
 private
   FValue_: Integer;
 public
   function GetValue_: Integer;
   procedure SetValue_(const Value: Integer);
   property Value_: Integer read GetValue_ write SetValue_;
 end;

 TMyOtherClass=class(TComponent, IMyInterface)
 private
   FMyInterface: IMyInterface;
 protected
   function GetValue_: Integer;
   procedure SetValue_(const Value: Integer);
 public
   property MyInterface: IMyInterface read FMyInterface implements IMyInterface;
 published
   property Value_: Integer read GetValue_ write SetValue_;
 end;

function TMyOtherClass.GetValue_: Integer;
begin
  Result := MyInterface.Value_;
end;

procedure TMyOtherClass.SetValue_(const Value: Integer);
begin
MyInterface.Value_:=Value;
end;

Последние два метода не очень красивые, т.к. просто вызывают свойство вложенного объекта. Можно ли решить задачу более красиво?


 
Romkin ©   (2006-08-01 14:08) [1]

У интерфейса только одна секция, public. Как бы ты ни изворачивался :)


 
Priest ©   (2006-08-01 14:13) [2]

Да я понимаю. Но смысл в том, чтобы некоторые свойства интерфейса сделать видимыми в Дизайн-Тайм у компонента.... Надоело писать однотипный код :(


 
Romkin ©   (2006-08-01 14:17) [3]

Сделай потомка класса и перемести проперти.



Страницы: 1 вся ветка

Скачать: CL | DM;



Память: 0.45 MB
Время: 0.026 c
15-1156504684
syte_ser78
2006-08-25 15:18
2006.09.17
помогите с запросом


1-1154869659
Redline
2006-08-06 17:07
2006.09.17
OnMessage


15-1156756095
Михель
2006-08-28 13:08
2006.09.17
Подскажите софт, чтобы сделать коллаж!


6-1146115348
sadel
2006-04-27 09:22
2006.09.17
Работа с telnet


15-1156611625
Loginov Dmitry
2006-08-26 21:00
2006.09.17
Многоязыковая поддержка




   Наверх