很简单呀。如下代码:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
CheckBox1: TCheckBox;
CheckBox2: TCheckBox;
CheckBox3: TCheckBox;
CheckBox4: TCheckBox;
CheckBox5: TCheckBox;
CheckBox6: TCheckBox;
CheckBox7: TCheckBox;
CheckBox8: TCheckBox;
CheckBox9: TCheckBox;
CheckBox10: TCheckBox;
Edit1: TEdit;
procedure CheckBox1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.CheckBox1Click(Sender: TObject);
var i:integer;
begin
edit1.Text :='';
for i:=0 to ComponentCount-1 do
if (Components is tcheckbox) then
if (Components as tcheckbox).Checked then
edit1.text:=edit1.text+'1'
else
edit1.text:=edit1.text+'0';
end;
end.
一个窗口,10个checkbox1-checkbox10,一个edit1,
建立checkbox1的onclick事件,其它checkbox2-checkbox10的onclinck全指向checkbox1的onclick事件。
试试上面的代码吧,完全符合你的要求。