掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
ライブラリにあるFormに値をSet (ID:37982)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
Formの雛形を作っておいて、色々なProjectから使いまわしたいということだと思うのですが。 (例えばプログラムのバージョン情報を表示するフォームなど) >みなさんはこういった状況でどのように作成しますか、意見聞かせてください。 私はそのような場合継承ではなく必要な変数の数だけグローバルな関数と手続きをいちいち書いています。 >Set(Def1、Def2、Def3、Def4、Def5:Integer; > Float1、Float2、Float3 :Double; > Comment1、Comment2、Comment3:String;); なら、 interface function GetDef1: Integer; procedure SetDef1(Value: Integer); function GetDef2: Integer; procedure SetDef2(Value: Integer); ... function GetComment2: String; procedure SetComment2(Value: String); function GetComment3: String; procedure SetComment3(Value: String); そして呼び出す側でいちいち汎用フォームをCreateしなくてもすむように、これらの関数・手続きの中で汎用フォームがCreateされていなかったらCreateするようにしています。 implementation procedure CreateForm; //フォームがCreateされていなければCreateする var i: Integer; begin if not(Assigned(LibForm)) then begin LibForm := TLibForm.Create(Application); end else begin for i := 0 to Screen.CustomFormCount-1 do begin if (Screen.CustomForms[i].ClassName = TLibForm.ClassName) then Exit; end; LibForm := TLibForm.Create(Application); end; end; function GetDef1: Integer; begin CreateForm; Result := LibForm.Def1; end; procedure SetDef1(Value: Integer); begin CreateForm; LibForm.Def1 := Value; end; ... こんな感じで。 >CreateしたものをどのタイミングでFreeにしてあげるかよくわからないです。 ShowModalで表示させる場合は別ですが、汎用FormのOnCloseイベントでActionをcaFreeにすれば汎用フォームを閉じたら自動でFreeされるようになります。
←解決時は質問者本人がここをチェックしてください。
更新する
戻る
掲示板システム
Copyright 2021 Takeshi Okamoto All Rights Reserved.