TPanel
에서 파생 된 복합 구성 요소에서 하위 구성 요소의 연결 속성을 설정하고 얻는 유일한 목적을 가진 속성을 게시하려고합니다. 폼에 복합 요소를 추가 할 때마다 액세스 위반이 발생합니다.복합 구성 요소에 하위 구성 요소의 속성을 게시하는 방법은 무엇입니까?
'MyRuntimePackage.bpl'모듈의 주소 12612D86에서 액세스가 위반됩니다. 주소 00000080. 나는
TLabel
하고PopupMenu
속성을 사용하여 간단한 예를 준비했지만 폼/프레임에 복합 구성 요소를 배치 할 때 난 여전히 같은 문제가
의 읽기.
런타임 패키지
uses
StdCtrls, Menus, ExtCtrls, Classes;
type
TTestCompoundComponent = class(TPanel)
private
FSubCmp : TLabel;
function GetLabelPopupMenu() : TPopupMenu;
procedure SetLabelPopupMenu(AValue : TPopupMenu);
protected
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
public
constructor Create(AOwner : TComponent); override;
destructor Destroy(); override;
published
property LabelPopupMenu : TPopupMenu read GetLabelPopupMenu write SetLabelPopupMenu;
end;
...
function TTestCompoundComponent.GetLabelPopupMenu() : TPopupMenu;
begin
Result := FSubCmp.PopupMenu;
end;
procedure TTestCompoundComponent.SetLabelPopupMenu(AValue : TPopupMenu);
begin
if(GetLabelPopupMenu() <> AValue) then
begin
if(GetLabelPopupMenu() <> nil)
then GetLabelPopupMenu().RemoveFreeNotification(Self);
FSubCmp.PopupMenu := AValue;
if(GetLabelPopupMenu() <> nil)
then GetLabelPopupMenu().FreeNotification(Self);
end;
end;
procedure TTestCompoundComponent.Notification(AComponent: TComponent; Operation: TOperation);
begin
inherited;
if((AComponent = GetLabelPopupMenu()) AND (Operation = opRemove))
then SetLabelPopupMenu(nil);
end;
constructor TTestCompoundComponent.Create(AOwner : TComponent);
begin
inherited;
FSubCmp := TLabel.Create(nil);
FSubCmp.Parent := Self;
end;
destructor TTestCompoundComponent.Destroy();
begin
FSubCmp.Free;
inherited;
end;
디자인 타임 패키지 FSubCmp
가 작성되기 전에 Notification()
건축 중에 opInsert
통지를 받으면
procedure Register;
begin
RegisterComponents('MyTestCompoundComponent', [TTestCompoundComponent]);
end;
알림 메서드에서 상속받은 것을 잊어 버렸습니다. – kobik
@kobik : 네가 맞아요, 고마워요! 질문을 업데이트했습니다. – ExDev