Вниз
Скачать: 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.44 MB
Время: 0.039 c
1-1155006078
vladimirg88
2006-08-08 07:01
2006.09.17
Координаты картинки


1-1154927477
Spectrum2
2006-08-07 09:11
2006.09.17
TNMUUProcessor


15-1156848676
memo_1
2006-08-29 14:51
2006.09.17
ошибка обновления


2-1156333098
rr
2006-08-23 15:38
2006.09.17
Как построчно прочитать файл


1-1155024509
npr2
2006-08-08 12:08
2006.09.17
обмен сообщениями между окнами в приложении




   Наверх