方案一 让他们的名字都有规律,就可以通过TComponent::FindCompoent()方法来查询~~ 比如: CheckBox1对应Edit1 CheckBox2对应Edit2 ... CheckBox30对应Edit30 赋值相同的事件CheckBoxClick(); procedure TForm1.CheckBoxClick(Sender: TObject); var vEdit: TEdit; vName: string; begin vName := 'Edit' + Copy(TCheckBox(Sender).Name, Length('CheckBox'), MaxInt); vEdit := TEdit(FindComponent(vName)); if Assigned(vEdit) then vEdit.Text := TCheckBox(Sender).Caption; end;方案二 动态创建,使用数组和TComponent::Tag属性来区分~~ 赋值相同的事件CheckBoxClick(); FEditList: array[1..30] of TEdit;procedure TForm1.CheckBoxClick(Sender: TObject); begin FEditList[TCheckBox(Sender).Tag].Text := TCheckBox(Sender).Caption; end;
你应该有10个edit,把你的10个edit的tag值依次设置为1,2,3,...10; 然后把你的对应tag为1的三个checkbox的tag设置为1; 依次类推设置完毕; 然后在程序中可以循环处理: 声明一个checkbox的onclick事件的函数; 所有的checkbox都调用; 判断 if (sender as TCheckbox).checked then begin if (sender as tcheckbox).tag=1 then begin edit1.text:=edit1.text+checkbox1.caption; end; ...... 所有的tag判断一遍 end; if not checked then
让他们的名字都有规律,就可以通过TComponent::FindCompoent()方法来查询~~
比如:
CheckBox1对应Edit1
CheckBox2对应Edit2
...
CheckBox30对应Edit30
赋值相同的事件CheckBoxClick();
procedure TForm1.CheckBoxClick(Sender: TObject);
var
vEdit: TEdit;
vName: string;
begin
vName := 'Edit' + Copy(TCheckBox(Sender).Name, Length('CheckBox'), MaxInt);
vEdit := TEdit(FindComponent(vName));
if Assigned(vEdit) then vEdit.Text := TCheckBox(Sender).Caption;
end;方案二
动态创建,使用数组和TComponent::Tag属性来区分~~
赋值相同的事件CheckBoxClick();
FEditList: array[1..30] of TEdit;procedure TForm1.CheckBoxClick(Sender: TObject);
begin
FEditList[TCheckBox(Sender).Tag].Text := TCheckBox(Sender).Caption;
end;
然后把你的对应tag为1的三个checkbox的tag设置为1;
依次类推设置完毕;
然后在程序中可以循环处理:
声明一个checkbox的onclick事件的函数;
所有的checkbox都调用;
判断
if (sender as TCheckbox).checked then
begin
if (sender as tcheckbox).tag=1 then
begin
edit1.text:=edit1.text+checkbox1.caption;
end;
......
所有的tag判断一遍
end;
if not checked then