掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
コンポーネント内の設計修正するには? (ID:18228)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
ちょっと面白そう(?)だったのでやってみました. ご希望の仕様かどうか,また実用性があるのかは不明です. MyButtonPanel.pasで保存し,MyButtonPanelをコンポーネントとして登録 して下さい. ただし,Delphi6以上専用です.質問された方はDelphiのバージョンが 書かれていないので,Delphi5以前であっても文句はなしということで... unit MyButtonPanel; //==================================================================== // サブコンポーネント // TPanel派生のTMyButtonPanelの上にButtonが配置されたもの // TPanelに設計時にTButtonを配置する場合との違いは,TMyButtonPanelの // オブジェクトインスペクタにButtonというプロパティがあり,そのプロ // パティ(イベントも含む)が設定可能なこと // Delphi6以降専用 //==================================================================== interface uses SysUtils, Classes, Controls, ExtCtrls,StdCtrls,Forms; type TMyInternalButton = class; TMyButtonPanel = class(TPanel) private { Private 宣言 } protected { Protected 宣言 } FButton : TMyInternalButton; procedure Notification(AComponent: TComponent; Operation: TOperation);override; procedure SetParent(AParent: TWinControl); override; public { Public 宣言 } constructor Create(AOwner: TComponent); override; destructor Destroy; override; published { Published 宣言 } property Button : TMyInternalButton read FButton; end; TMyInternalButton = class(TButton) private { Private 宣言 } protected { Protected 宣言 } public { Public 宣言 } constructor Create(AOwner: TComponent); override; published { Published 宣言 } end; procedure Register; implementation procedure Register; begin RegisterComponents('Samples2', [TMyButtonPanel]); end; { TMyButtonPanel } //==================================================================== // Button(サブコンポーネント)を乗せるPanelの生成 //==================================================================== constructor TMyButtonPanel.Create(AOwner: TComponent); begin inherited; FButton:=TMyInternalButton.Create(AOwner); FButton.Parent:=Self; end; //==================================================================== // Button(サブコンポーネント)を乗せるPanelの破棄 //==================================================================== destructor TMyButtonPanel.Destroy; begin FButton.Free; inherited; end; //==================================================================== // Button(サブコンポーネント)が削除された場合を考慮 //==================================================================== procedure TMyButtonPanel.Notification(AComponent: TComponent; Operation: TOperation); begin inherited Notification(AComponent, Operation); if csDestroying in ComponentState then exit; if (Operation=opRemove) then begin if (AComponent=TComponent(FButton)) then begin FButton:=nil; end; end; end; //==================================================================== // Button(サブコンポーネント)に名前を付ける // 名前がないとイベント等が作成できない //==================================================================== procedure TMyButtonPanel.SetParent(AParent: TWinControl); var AForm : TCustomForm; begin inherited; if Parent=nil then exit; if csDesigning in ComponentState then begin AForm:=GetParentForm(Self); FButton.Name:=AForm.Designer.UniqueName('Button'); end; end; { TMyInternalButton } //==================================================================== // Button(サブコンポーネントでTMybuttonPanelのプロパティ)の生成 // SetSubComponentでサブコンポーネントとして設定 //==================================================================== constructor TMyInternalButton.Create(AOwner: TComponent); begin inherited Create(AOwner); SetSubComponent(True); end; end.
←解決時は質問者本人がここをチェックしてください。
更新する
戻る
掲示板システム
Copyright 2021 Takeshi Okamoto All Rights Reserved.