TPanel
から派生したコンパウンドコンポーネントでは、サブコンポーネントのリンケージプロパティを設定し取得する唯一の目的を持つプロパティを公開しようとしています。コンパウンドコンポーネントをフォームに追加するたびに、アクセス違反が発生します。複合コンポーネントにサブコンポーネントのプロパティを公開するにはどうすればよいですか?
モジュール 'MyRuntimePackage.bpl'のアドレス12612D86でアクセス違反が発生します。アドレス00000080.
の読む私はTLabel
とそのPopupMenu
プロパティを使用して簡単な例を用意しましたが、フォーム/フレーム上の化合物成分を配置するとき、私はまだ同じ問題を抱えています。
Runtimeパッケージ:
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
通知を受信したときにGetLabelPopupMenu()
で
procedure Register;
begin
RegisterComponents('MyTestCompoundComponent', [TTestCompoundComponent]);
end;
通知メソッド – kobik
で継承したことを忘れた@kobik:ありがとうございます!私は質問を更新しました – ExDev