I struggle a bit with understanding generics and how they can and cannot be used.
I have a generic TControlMediator class:
TControlMediator<C, T> = class private FMediatedComponent: C; public constructor Create(ComponentToMediate: C); function GetValue: T; virtual; abstract; procedure SetValue(Value: T); virtual; abstract; property MediatedControl: C read FMediatedComponent; end;
Then I subclass "concret" for each type of control that I want to mediate:
TEditMediator = class(TControlMediator<TEdit, string>) public function GetValue: string; override; procedure SetValue(Value: string); override; end;
So far, everything is working fine. Problems arise, though, when I need a descendant of TControlMediator, or taking TControlMediator as a method parameter:
TViewMediator = class private FControlMediators: TList<TControlMEdiator<C, T>>; public procedure registerMediator(AControlMediator: TControlMediator<C, T>); procedure unregisterMediator(AControlMediator: TControlMediator<C, T>); end;
The compiler stops with fatal errors:
[DCC Error] mediator.pas(23): E2003 Undeclared identifier: 'C' [DCC Error] mediator.pas(28): E2007 Constant or type identifier expected
Does anyone have any clues on how this should be done?
Vegar source share