我的一张页面中有27checkbox,想通过创建数组使他们在保存时通过循环进行判断。
之前都没接触过checkbox数组这方便的信息,希望大家帮帮忙,越详细越好。
在页面是怎么创建的,还有他们是怎么定义的,怎么进行判断他们的checked的属性。
之前都没接触过checkbox数组这方便的信息,希望大家帮帮忙,越详细越好。
在页面是怎么创建的,还有他们是怎么定义的,怎么进行判断他们的checked的属性。
var i:Integer;
chkBox:TCheckBox;
begin
for i:=0 to self.ComponentCount-1 do//循环当前窗体上所有的控件
begin
if self.Components[i] is TCheckBox then//判断是不是TCheckBox
begin
chkBox:=TCheckBox(self.Components[i]);
//干你的活....chkBox就是当前的TCheckBox
end;
end;
end;
你这样貌似还不能支持多选,你试试就知道了。如果不行的话 劝lz用TCheckListBox,这个对于checkbox很多的时候很人性化。呵呵
var
Labels : Array of TLabel;
i : Integer;
SetLength(labels, 6);
Labels[0] := lbl1;
Labels[1] := lbl2;
Labels[2] := lbl3;
Labels[3] := lbl4;
Labels[4] := lbl5;
Labels[5] := lbl6; for i := 0 to 5 do
showmessage(labels[i].caption);
我的代码具体是:
for i:=0 to self.ComponentCount-1 do//循环当前窗体上所有的控件
begin
if self.Components[i] is TCheckBox then//判断是不是TCheckBox
begin
chkBox:=TCheckBox(self.Components[i]);
if chkBox.Checked =true then
begin
a:=chkBox.Caption;
RightListBox.Items.Add(a);
with UserRQuery do
begin
close;
sql.Clear ;
sql.Add('select RightID from V_Right where tbExplain=:RName');
parameters.ParamByName('RName').Value :=chkBox.Caption ;
open;
end;
b :=UserRQuery.fieldbyname('RightID').Value;
end;
with DelQuery do
begin
close;
sql.Clear ;
sql.Add('Insert into tb_UserRight values(:ID2,:ID1)');
parameters.ParamByName('ID1').Value :=UpQuery.fieldbyname('UserID').Value;
parameters.ParamByName('ID2').Value :=b;
execsql;
end;
end;能告诉我TCheckListBox的具体用法吗,它看起来像ListBox,也是把Checkbox一个个放入CheckListBox吗?问的比价傻,还请见谅!没使用过CheckListBox,不知它有什么特点
添加类容
CheckListBox1.Items.Add('是否超级帐户');
CHECKListBox1.Checked[0] := g_Player.m_boSuperMan;
CheckListBox1.Items.Add('是否是管理模式');
CHECKListBox1.Checked[1] := g_Player.m_boAdminMode;
CheckListBox1.Items.Add('是否锁定仓库');
CHECKListBox1.Checked[2] := g_Player.m_boPasswordLocked;
CheckListBox1.Items.Add('是否剔除下线');
CHECKListBox1.Checked[3] := g_Player.m_boKickFlag;
CheckListBox1.Items.Add('是否能取回物品');
取值:
case CheckListBox1.ItemIndex of
0 : g_Player.m_boSuperMan := CHECKListBox1.Checked[0];
1 : g_Player.m_boAdminMode := CHECKListBox1.Checked[1];
2: g_Player.m_boPasswordLocked := CHECKListBox1.Chec
end;
这是我的1个例子,lz自己试试。
我最近把分数都用光了,能给大家的分不多,真是抱歉,不过以后等我有分了,会多加些。
(*^__^*) 嘻嘻……以后还希望大家多帮帮忙