掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
TPopupBoxとほぼ同じコードで見た目が違うのは何故でしょう (ID:151182)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
AAAAAさん 有難うございます。 最終的には、mamさんに教えて頂きましたクラスヘルパーを使わせて頂き次の様なコードになりました。 使い方としては、 ・デザイン時に名称表示用のItemsとコード設定用のItemsExを設定します ・データベースから取得した値(コード)でPopupBoxの表示名称を設定する際は、TextEx := '1';などと設定する事で対応する名称が表示されます ・PopuoBoxで選択した名称に対するコードを取り出す場合はTextExを参照します ※DoEndUpdateをオーバーライドしていますが、これでベストかは自信がないです(汗) unit MmPopupBox; interface uses System.SysUtils, System.Classes, FMX.Types, FMX.Controls, FMX.Controls.Presentation, FMX.StdCtrls, FMX.ExtCtrls; type // クラスヘルパー(Privateメソッドは扱える様になる模様) TPopupBoxHelper=class helper for TPopupBox function GetItemIndexHelper():Integer; procedure SetItemIndexHelper(Value:Integer); end; // TMmPopupBoxクラス TMmPopupBox = class(TPopupBox) private FItemsEx: TStrings; FItemIndexEx: Integer; FTextEx: String; { Private 宣言 } procedure SetItemsEx(Value: TStrings); procedure SetTextEx(Value: String); procedure DoEndUpdate; override; protected { Protected 宣言 } public { Public 宣言 } constructor Create(AOwner: TComponent); override; destructor Destroy; override; property ItemIndexEx: Integer read FItemIndexEx write FItemIndexEx; published { Published 宣言 } property ItemsEx: TStrings read FItemsEx write SetItemsEx; property TextEx: String read FTextEx write SetTextEx; end; procedure Register; implementation procedure Register; begin RegisterComponents('Original', [TMmPopupBox]); end; { TPopupBoxHelper } function TPopupBoxHelper.GetItemIndexHelper: Integer; begin with self do result := FItemIndex; end; procedure TPopupBoxHelper.SetItemIndexHelper(Value: Integer); begin with self do SetItemIndex(Value); end; { TMmPopupBox } {------------------------------------------------------------------------------- ■ コンストラクタ -------------------------------------------------------------------------------} constructor TMmPopupBox.Create(AOwner: TComponent); begin inherited; // 拡張 FItemsEx := TStringList.Create; FItemIndexEx := -1; end; {------------------------------------------------------------------------------- ■ デストラクタ -------------------------------------------------------------------------------} destructor TMmPopupBox.Destroy; begin FreeAndNil(FItemsEx); inherited; end; {------------------------------------------------------------------------------- ■ 変更完了時のVirtualメソッドをオーバーライド @summary PopupBoxで選択された後のインデックスを取得し、コードテキストも取得 -------------------------------------------------------------------------------} procedure TMmPopupBox.DoEndUpdate; begin inherited; if ItemIndexEx <> ItemIndex then begin FItemIndexEx := ItemIndex; FTextEx := ItemsEx[FItemIndexEx]; end; end; {------------------------------------------------------------------------------- ■ ItemsEx(コード用拡張Items)の設定 -------------------------------------------------------------------------------} procedure TMmPopupBox.SetItemsEx(Value: TStrings); begin FItemsEx.Assign(Value); end; {------------------------------------------------------------------------------- ■ TextEx(コード用拡張Text)プロパティの設定 @summary コードテキストからインデックスを取得しPopupBoxの表示内容も書き替え -------------------------------------------------------------------------------} procedure TMmPopupBox.SetTextEx(Value: String); begin // Valueと現在のコード(TextEx)が異なる場合 if Value <> FTextEx then begin FTextEx := Value; FItemIndexEx := ItemsEx.IndexOf(Value); SetItemIndexHelper(FItemIndexEx); end; end; end.
←解決時は質問者本人がここをチェックしてください。
戻る
掲示板システム
Copyright 2020 Takeshi Okamoto All Rights Reserved.