掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
EditのEnabled=False処理で (ID:150127)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
遅くなりましたが AAAさん > TX = class(TWinControl) そうですね、これが一番ラクチンですね。 TCustomEditとかTCustomComboBoxとかそれぞれのコントロール別の判定不要で、is TWinControl で済みますから。 そんなわけで、正攻法?と組み合わせたのを作ってみました procedure SetEnabledCtrl(aCtrl: TControl; aEnabled: Boolean); implementation type //誤魔化し用 TWCtrl =class(TWinControl) public property Color; property Font; end; TCALink =class(TControlActionLink) private FAction :TAction; FWClient :TWCtrl; public constructor Create(AClient: TObject); override; destructor Destroy; override; protected function IsEnabledLinked: Boolean; override; procedure AssignClient(AClient: TObject); override; procedure SetEnabled(Value: Boolean); override; end; constructor TCALink.Create(AClient: TObject); begin inherited Create(AClient); FAction := TAction.Create(nil); Action := FAction; end; destructor TCALink.Destroy; begin FAction.Free; inherited Destroy; end; function TCALink.IsEnabledLinked: Boolean; begin //無条件リンクしていると判定 Result := True; end; procedure TCALink.AssignClient(AClient: TObject); begin inherited AssignClient(AClient); //↓↓↓↓↓↓ (※)ココ if AClient is TWinControl then FWClient := TWCtrl(AClient); end; procedure TCALink.SetEnabled(Value: Boolean); begin inherited SetEnabled(Value); if FWClient <> nil then begin if Value then begin FWClient.Font.Color := clWindowText; FWClient.Color := clWindow; end else begin FWClient.Font.Color := clGray; FWClient.Color := clLtGray; end; end; end; procedure SetEnabledCtrl(aCtrl: TControl; aEnabled: Boolean); var wcal :TCALink; begin wcal := TCALink.Create(aCtrl); try wcal.SetEnabled(aEnabled); finally wcal.Free; end; end; これで、「おお!いい感じ!」などと自己満足していましたが、 TCheckBoxとかも対象にしたとき、フォントやら背景やら変わってしまって、よろしくありませんでした。 上記ソース内、(※)ココ の部分を、フォントとか更新してもいいコントロールであるかの判定にすると、 使えるようになりそうです。 単純に考えて、 is TCustomEdit とか is TCustomComboBox でしょうけど。
←解決時は質問者本人がここをチェックしてください。
戻る
掲示板システム
Copyright 2020 Takeshi Okamoto All Rights Reserved.