당신은 여전히 동일한 서명이없는 경우에도, 서브 클래스 내에서 상속 TCollection.Create를 호출 할 수 있습니다 : 원래 포스터의 의견에 따라 경찰
:
TMyCollectionItem = class(TCollectionItem)
private
FIntProp: Integer;
procedure SetIntProp(const Value: Integer);
public
property IntProp: Integer read FIntProp write SetIntProp;
end;
TMyCollection = class(TCollection)
public
constructor Create(AOwner: TComponent);virtual;
end;
{ TMyCollection }
constructor TMyCollection.Create(AOwner: TComponent);
begin
inherited Create(TMyCollectionItem); // call inherited constructor
end;
편집을 , "트릭"은 새 생성자를 오버로드로 표시하는 것입니다. 오버로드이므로 TCollection 생성자에 대한 액세스를 숨기지 않습니다.
TMyCollection = class(TCollection)
public
constructor Create(AOwner: TComponent);overload; virtual;
end;
TMyItem = class(TCollectionItem)
private
FInt: Integer;
public
property Int: Integer read FInt;
end;
TMyItems = class(TMyCollection)
public
constructor Create(AOwner: TComponent);override;
end;
implementation
{ TMyCollection }
constructor TMyCollection.Create(AOwner: TComponent);
begin
inherited Create(TCollectionItem);
end;
{ TMyItems }
constructor TMyItems.Create(AOwner: TComponent);
begin
inherited Create(TMyItem);
inherited Create(AOwner); // odd, but valid
end;
end.
문제는 내가 상속 의 2 개 수준을 가지고있는 코드는 다음과 같은 : TMyCollection = 클래스 (된 TCollection) .... TMyCollection의 생성자가 생성자 (AOwner 만들기입니다 : TComponent); TMyItems = 클래스 (TMyCollection) TMyItems의 생성자 : 생성자 Create (AOwner : TComponent); TMyItems에서 상속 된 생성자를 호출하려고하면 ItemClass가 새로 생성되어 컬렉션에 전달되어야하므로 원하는 항목이 아닌 TMyCollection의 생성자를 호출합니다 ... – user1512094
New ItemClass도 TMyCollectionItem에서 상속됩니다. TMyCollectionItem의 모든 속성과 이벤트를 갖습니다. – user1512094