掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
同じコントロールのプロパティにアクセスするには? (ID:13383)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
クリックするたびに同じ GroupIndex どうしで排他的に色を変化させるコンポを つくり、動的に作成してテストしました。参考にしてください。 unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TGroupLabel = class(TLabel) private FGroupIndex:integer; public procedure AllClear; published property GroupIndex:integer read FGroupIndex write FGroupIndex; end; TForm1 = class(TForm) procedure FormCreate(Sender: TObject); private { Private 宣言 } public procedure LabelClick(Sender: TObject); end; var Form1: TForm1; implementation {$R *.dfm} procedure TGroupLabel.AllClear; var i:integer; f:TForm; begin if FGroupIndex = 0 then exit; if Owner is TForm then begin f := TForm(Owner); for i := 0 to f.ComponentCount-1 do if f.Components[i] is TGroupLabel then if TGroupLabel(f.Components[i]).GroupIndex = FGroupIndex then TGroupLabel(f.Components[i]).Color := clBtnFace; end; end; procedure TForm1.FormCreate(Sender: TObject); var i:integer; gl:TGroupLabel; begin for i := 0 to 3 do begin gl := TGroupLabel.Create(self); gl.Parent := self; gl.GroupIndex := 123; gl.Top := 10; gl.Left := 120*i+10; gl.Caption := 'GroupLabel '+IntToStr(i); gl.OnClick := LabelClick; end; end; procedure TForm1.LabelClick(Sender: TObject); begin if Sender is TGroupLabel then begin TGroupLabel(Sender).AllClear; TGroupLabel(Sender).Color := clAqua; end; end; end.
←解決時は質問者本人がここをチェックしてください。
戻る
掲示板システム
Copyright 2021 Takeshi Okamoto All Rights Reserved.