![]() |
| ||
|
|
Новости |
Поиск |
FAQ |
Статьи |
Книги |
Новости VCL
| | Форумы ЧАТ |
Орешник |
|
| |||
| |||
« предыдущая ветвь | форум | следующая ветвь »
Делегирование реализации интерфейсов
Priest © (2006-08-01 13:48:00)Есть класс, в котором реализуется интерфейс. В дргуом классе также необходимо реализовать тот же интерфейс, но непоторые свойства нужны 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:17:00) [1]Сделай потомка класса и перемести проперти.
Priest (2006-08-01 14:13:00) [2]Да я понимаю. Но смысл в том, чтобы некоторые свойства интерфейса сделать видимыми в Дизайн-Тайм у компонента.... Надоело писать однотипный код :(
Romkin (2006-08-01 14:08:00) [3]У интерфейса только одна секция, public. Как бы ты ни изворачивался :)