Вниз
Скачать: 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.036 c
15-1156408690
KygECHuK
2006-08-24 12:38
2006.09.17
StarTeam


15-1156360666
LBVF
2006-08-23 23:17
2006.09.17
Откуда можно скачать Delphi 1.0


2-1156452053
ronyn
2006-08-25 00:40
2006.09.17
Как создать пустой фильтр?


1-1155040004
ZX48
2006-08-08 16:26
2006.09.17
RaveReports


15-1156524261
Вася
2006-08-25 20:44
2006.09.17
Функции Explode и StrLowwer(StrUpper)




   Наверх