关于CheckBox(50分)

B

bearyan

Unregistered / Unconfirmed
GUEST, unregistred user!
如下所示,我动态生成9*9的checkbox阵列;
procedure TForm1.Button1Click(Sender: TObject);
var
Chbx : TCheckBox;
i : Byte;
j : Byte;
begin
for j:= 0 to 8do
begin
for i := 0 to 8do
begin
ChBx:= TCheckBox.create(self);
chbx.top:=10 + (i*10);
chbx.left:=11 + (j*10);
chbx.width:=10;
chbx.height:=10;
chbx.parent:=self;
chbx.show;
end;
end;
end;

我想得到如下效果,当选择左上角第一个时,输出128;第二个时,输出64……第八个时,输出1;同时选择八个,输出255;
八列都是如此处理,请问该如何解决???
请提供具体的解决方法!立刻给分!~~
 
H

hfghfghfg

Unregistered / Unconfirmed
GUEST, unregistred user!
你用 chbx.tag 做处理
 
B

bearyan

Unregistered / Unconfirmed
GUEST, unregistred user!
能给出详细的解决方案吗?如能解决,立刻给分,我在线等
 
H

hfghfghfg

Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons;
type
TForm1 = class(TForm)
BitBtn1: TBitBtn;
procedure BitBtn1Click(Sender: TObject);
procedure CheckBox1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
implementation
{$R *.dfm}
uses math;
procedure TForm1.BitBtn1Click(Sender: TObject);
var
Chbx: TCheckBox;
i: Byte;
j: Byte;
begin
for j := 0 to 7do
begin
for i := 0 to 7do
begin
ChBx := TCheckBox.create(self);
chbx.top := 10 + (i * 10);
chbx.left := 11 + (j * 10);
chbx.width := 10;
chbx.height := 10;
chbx.parent := self;
chbx.show;
//
chbx.tag := j * 10 + i;
chbx.OnClick := CheckBox1Click;
end;
end;
end;

procedure TForm1.CheckBox1Click(Sender: TObject);
var
Chbx: TCheckBox;
aChbx: TCheckBox;
i: Byte;
j: Byte;
idx, atag: integer;
s: integer;
begin
Chbx := TCheckBox(Sender);
j := Chbx.tag div 10;
i := Chbx.tag mod 10;
s := 0;
for idx := 0 to Chbx.Parent.ControlCount - 1do
if Chbx.Parent.Controls[idx] is TCheckBox then
begin
aChbx := TCheckBox(Chbx.Parent.Controls[idx]);
if not aChbx.Checked then
Continue;
atag := aChbx.tag;
if (atag mod 10) = i then
begin

s := s + 1 shl (7 - (atag div 10))
end;
end;

showmessage(format('行:%d 和:%d', [1+i, s]));
end;

end.
 
H

hfghfghfg

Unregistered / Unconfirmed
GUEST, unregistred user!
八列 是
for j := 0 to 7do
begin
for i := 0 to 7do
 
B

bearyan

Unregistered / Unconfirmed
GUEST, unregistred user!
太感谢了,我想问问tag是什么意思??
 
H

hfghfghfg

Unregistered / Unconfirmed
GUEST, unregistred user!
tag 就是个 标记 而已
 

Similar threads

S
回复
0
查看
611
SUNSTONE的Delphi笔记
S
S
回复
0
查看
499
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
1K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
467
import
I
顶部