Вниз
Скачать: 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
2-1156322233
Id
2006-08-23 12:37
2006.09.17
Соединение с базой


6-1146415451
CyMKuH
2006-04-30 20:44
2006.09.17
IP & Internet


3-1152797535
samalex
2006-07-13 17:32
2006.09.17
не работает функция upper


2-1156749072
shake
2006-08-28 11:11
2006.09.17
выборка из dbgrid


2-1156775394
AlexanderMS
2006-08-28 18:29
2006.09.17
Флаги.




   Наверх