~因为明天要交~所以没时间想var s:string;
begin
s:=StringOfChar('0',32);
if Chk01.Checked then s[1]:='1';
if Chk02.Checked then s[2]:='1';
if Chk03.Checked then s[3]:='1';
if Chk04.Checked then s[4]:='1';
if Chk05.Checked then s[5]:='1';
if Chk06.Checked then s[6]:='1';
if Chk07.Checked then s[7]:='1';
一共有32个...怎么简化
Chk01是复选框~谢谢
begin
s:=StringOfChar('0',32);
if Chk01.Checked then s[1]:='1';
if Chk02.Checked then s[2]:='1';
if Chk03.Checked then s[3]:='1';
if Chk04.Checked then s[4]:='1';
if Chk05.Checked then s[5]:='1';
if Chk06.Checked then s[6]:='1';
if Chk07.Checked then s[7]:='1';
一共有32个...怎么简化
Chk01是复选框~谢谢
for i := 0 to ControlCount - 1 do
begin
if Controls[i].ClassType = TCheckBox then
根据命名的规则获得名称后面的数字 Copy(Controls[i].Name, x, N);
这个数字作为数组的下标这样就可以完成你所说的功能了吧
for i:=1 to componentcount do
begin
if i<10 then str:='chk0'
else str:='chk'
if TCheckBox(FindComponent(str+inttostr(i)).checked then
s[i]:='1';
end;
for i := 0 to ControlCount - 1 do
begin
if Controls[i].ClassType = TCheckBox then
if Controls[i].Checked then
s[StrToInt(Copy(Controls[i].Name,6,2))] := '1';
end
end;