1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
| type
X = class
// ...
end;
Y = class(X)
// ...
end;
Z = class(X)
// ...
end;
A = class
protected
FRef : X;
public
constructor Create(ARef : X);
destructor Destroy; override;
end;
B = class(A)
private
function GetRef : Y;
public
constructor Create;
property Ref : Y read GetRef;
end;
C = class(A)
private
function GetRef : Z;
public
constructor Create;
property Ref : Z read GetRef;
end;
implementation
constructor A.Create(ARef : X);
begin
inherited Create;
FRef := ARef;
end;
destructor A.Destroy;
begin
FRef.Free;
inherited;
end;
constructor B.Create;
begin
inherited Create(Y.Create);
end;
function B.GetRef : Y;
begin
Result := Y(FRef);
end;
constructor C.Create;
begin
inherited Create(Z.Create);
end;
function C.GetRef : Z;
begin
Result := Z(FRef);
end; |
Partager