procedure TForm1.CheckBox1Click(Sender: TObject);
var
tmp:TComponent;
begin
if Sender is TCheckBox then
begin
tmp:=FindComponent('Edit'+copy((Sender as TCheckBox).Name,9,10));
if tmp is TEdit then
(tmp as TEdit).Enabled:= (Sender as TCheckBox).Checked;
end;
end;
var
tmp:TComponent;
begin
if Sender is TCheckBox then
begin
tmp:=FindComponent('Edit'+copy((Sender as TCheckBox).Name,9,10));
if tmp is TEdit then
(tmp as TEdit).Enabled:= (Sender as TCheckBox).Checked;
end;
end;
var
tmp:TComponent;
begin
if Sender is TCheckBox then
begin
tmp:=FindComponent('Edit'+copy((Sender as TCheckBox).Name,9,10));
if tmp is TEdit then
(tmp as TEdit).Enabled:= (Sender as TCheckBox).Checked;
end;
end;
Begin
Edit1.Enabled:=True;
End
else
Begin
Edit1.Enabled:=False;
End;
with Tcheckbox(FindComponent(checkbox + IntToStr(i))) do
begin
tEedit(findcomponent(edit+inttostr(i))).enabled=checked;
end;
end;
i:=0;
j:=29;
for i:=1 to 29 do
Begin
if CheckBox1.Checked then
Begin
Edit1.Enabled:=True;
End
else
Begin
Edit1.Enabled:=False;
End;
End;
把数字转换为i 就可以了。
var
E:TComponent;
begin
if Sender is TCheckBox then
begin
E:=FindComponent('Edit'+copy((Sender as TCheckBox).Name,9,10));
if E is TEdit then
(E as TEdit).Enabled:= (Sender as TCheckBox).Checked;
end;
end;
看上简单,其实也不难
E:array[1..24] of TEdit;分别设定CheckBox1..CheckBox24的Tag为1..24
在FormCreate事件中
E[1]:=Edit1;
E[2]:=Edit2;
...
E[24:=Edit24;在CheckBoxClick事件中(所有的CheckBoxX的OnClick事件都指向同一处代码):
E[(Sender as TComboBox).Tag].Enabled:=(Sender as TComboBox).Checked;
Begin
TEedit(findcomponent(edit+inttostr(i))).enabled=Tcheckbox(FindComponent(checkbox + IntToStr(i))).checked;
end;
我用copy 10你干嘛也用10,我决定用100,呵呵
procedure TForm1.CheckBox1Click(Sender: TObject);
begin
if CheckBox1.Checked then
Edit1.Enabled := True
else
Edit1.Enabled := False;
end;
或者写个过程
procedure CheckEnabled;
var
i: Integer;
begin
for i := 1 to 24 do
begin
if Assigned(FindComponent('CheckBox'+IntToStr(i)))
and Assigned(FindComponent('Edit'+IntToStr(i))) then
begin
if TCheckBox(FindComponent('CheckBox'+IntToStr(i))).Checked then
TEdit(FindComponent('Edit'+IntToStr(i))).Enabled := True
else
TEdit(FindComponent('Edit'+IntToStr(i))).Enabled := False;
end;
end;
end;
设置每个CheckBox的Tag属性为指向相应Edit的指针就可以了,不过要在程序中指定。其他的不用我说了吧?呵呵
TEdit(Pointer((Sender as TCheckBox).tag)).Enabled := (Sender as TCheckBox).Checked;
CheckBox1.Tag := integer(Edit1);
CheckBox2.Tag := integer(Edit2);
......
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
……
CheckBox1: TCheckBox;
CheckBox2: TCheckBox;
CheckBox3: TCheckBox;
……
procedure CheckBoxclick(Sender: TObject); //Method Added ……
procedure TForm1.CheckBoxClick(Sender: TObject);
var
t : TComponent;
begin
if Sender is TCheckBox then
begin
t:=FindComponent('Edit'+copy((Sender as TCheckBox).Name,9,1));
if t is TEdit then
(t as TEdit).Enabled:= (Sender as TCheckBox).Checked;
end;
end; 不过一定要记得在各个CheckBox的Click事件中选择定义的CheckBoxClick方法!
with TCheckbox(FindComponent(Checkbox+IntToStr(i))) do
begin
TEdit(findComponent(Edit+intToStr(i))).enabled:=checked;
end;
end;
确实不错!
TEdit(Pointer(Sender as TCheckbox).tag)).Enable:=(sender as TCheckBox).checked;
总结一下吧,大题有这么几种
用循环
for i:=1 to 24 do begin
with TCheckbox(FindComponent(‘Checkbox'+IntToStr(i))) do
begin
TEdit(findComponent('Edit'+intToStr(i))).enabled:=checked;
end;
end;
或直接引用TEdit(Pointer(Sender as TCheckbox).tag)).Enable:=(sender as TCheckBox).checked;
留给后来人:)