掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
自作コンポーネントの parent プロパティ (ID:44375)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
結局 http://stackoverflow.com/questions/6403217/how-to-set-a-tcustomcontrols-parent-in-create?answertab=active#tab-top の書き込みを参考にして AfterConstruction イベントを捕まえて 無理矢理 parent をセットしました。 簡単なテストでは問題はでていませんが、又何かでてきるかもしれません。 みなさんありがとうございました。 ↓はコンポーネントから関係する部分だけを抜き出したものです。 //------------------------------------------ // TKELV AfterConstruction イベント // ここで Parent プロパティをセット //------------------------------------------ procedure TKELV.AfterConstruction; var WrkTPoint : TPoint; // マウス座標の下にあるコンポーネント取り出し WrkTControl : TControl; WrkTWincontrol : TWincontrol; begin inherited; { if Assigned( FDebugMemo ) = True then FDebugMemo.Lines.Add( IntToStr( FDebugMemo.Lines.Count ) + 'AfterConstruction' ); Self.ParentBackground := False; Self.Color := clBlue; } //----------------// if ( csDesigning in Self.ComponentState ) = True then // 設計時はname プロパティの値はこのメソッドの後でセットされる。 begin GetCursorPos( WrkTPoint ); // マウス座標の下にあるコンポーネント取り出し WrkTControl := FindDragTarget( WrkTPoint, True ); if Assigned( WrkTControl ) = False then exit; if ( WrkTControl is TWinControl ) = False then exit; WrkTWincontrol := TWincontrol( WrkTControl ); if WrkTWincontrol <> Self.Parent then Self.Parent := WrkTWincontrol; end; if Assigned( FDebugMemo ) = True then FDebugMemo.Lines.Add( IntToStr( FDebugMemo.Lines.Count ) + 'AfterConstruction PA=' + Self.Parent.Name ); end;
←解決時は質問者本人がここをチェックしてください。
更新する
戻る
掲示板システム
Copyright 2021 Takeshi Okamoto All Rights Reserved.