掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
自作コンポーネント上のTEditのプロパティを保存させるには? (ID:28741)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
おそらくオブジェクトインスペクタ上でプロパティ名が黒で表示されない時点でプロパティの保存は無理かと思います。 フォームをエディタで表示した時点で設定が消えています。 >「AOwner」を指定するとプロパティは保存されますが、デザイン画面でコン>ポーネント内のTEditを直接選択出来てしまい、移動させたり、削除出来てし>まうなど問題があります。 仮に出来たとしてもプロパティを設定する事により移動とか可能になってしまいますよ >2つのTEditにアクセスするためのプロパティをそれぞれ2個ずつ記述すれ >ば良いのですが、プロパティが多くなりごちゃごちゃしてしまいそうなの >で、出来るならオブジェクトインスペクタでそれぞれグループ化されるよう>にしたいと考えています。 ですが下記のようにすればオブジェクトインスペクタ上でグループ化する事は可能です unit PanelEx; interface uses SysUtils, Classes, Controls, StdCtrls,ExtCtrls,Graphics; type TEditProperty = class(TPersistent) private FEdit : TEdit; FText : String; protected procedure SetText(Value:String); function GetText:String; procedure SetColor(Value:TColor); function GetColor:TColor; public constructor Create(AOwner: TComponent;Edit:TEdit); destructor Destroy;override; published property Text : String read GetText write SetText; property Color : TColor read GetColor write SetColor; end; TPanelEx = class(TPanel) private FEdit1 : TEdit; FEdit2 : TEdit; FEdit1Property : TEditProperty; FEdit2Property : TEditProperty; protected procedure SetEdit1(Value:TEdit); procedure SetEdit2(Value:TEdit); public constructor Create(AOwner: TComponent);override; destructor Destroy;override; published property Edit1 : TEditProperty read FEdit1Property write FEdit1Property; property Edit2 : TEditProperty read FEdit2Property write FEdit2Property; end; procedure Register; implementation //-------------------------------------------- // TEditProperty //-------------------------------------------- procedure TEditProperty.SetText(Value: string); begin if Assigned(FEdit) = True then FEdit.Text := Value; end; function TEditProperty.GetText; begin if Assigned(FEdit) = True then Result := FEdit.Text; end; procedure TEditProperty.SetColor(Value: TColor); begin if Assigned(FEdit) = True then FEdit.Color := Value; end; function TEditProperty.GetColor; begin if Assigned(FEdit) = True then Result := FEdit.Color; end; constructor TEditProperty.Create(AOwner: TComponent;Edit:TEdit); begin inherited Create; FEdit := Edit; end; destructor TEditProperty.Destroy; begin inherited Destroy; end; //-------------------------------------------- // TPanel //-------------------------------------------- procedure TPanelEx.SetEdit1(Value: TEdit); begin FEdit1.Assign(Value); end; procedure TPanelEx.SetEdit2(Value: TEdit); begin FEdit2.Assign(Value); end; constructor TPanelEx.Create(AOwner: TComponent); begin inherited Create(AOwner); FEdit1 := TEdit.Create(Self); FEdit1.Parent := Self; FEdit1.Left := 0; FEdit1.Top := 0; FEdit2 := TEdit.Create(Self); FEdit2.Parent := Self; FEdit2.Left := 0; FEdit2.Top := 20; FEdit1Property := TEditProperty.Create(Self,FEdit1); FEdit2Property := TEditProperty.Create(Self,FEdit2); end; destructor TPanelEx.Destroy; begin FEdit2Property.Free; FEdit1Property.Free; FEdit2.Free; FEdit1.Free; inherited Destroy; end; procedure Register; begin RegisterComponents('Component', [TPanelEx]); end; end.
←解決時は質問者本人がここをチェックしてください。
更新する
戻る
掲示板システム
Copyright 2021 Takeshi Okamoto All Rights Reserved.