在窗体上有
checkbox1,checkbox2,checkbox3,checkbox4,checkbox5
label1,label2,label3,label4,label5这些控件
想用一个循环实现
for i:=1 to 5 do
begin
if checkbox[i].checked=true then;//这里如何写
begin
label[i].caption:='0';//这里如何写
end;
end;
万分感谢!
checkbox1,checkbox2,checkbox3,checkbox4,checkbox5
label1,label2,label3,label4,label5这些控件
想用一个循环实现
for i:=1 to 5 do
begin
if checkbox[i].checked=true then;//这里如何写
begin
label[i].caption:='0';//这里如何写
end;
end;
万分感谢!
解决方案 »
- Indy组件TIDHttp改变了文字编码?
- 只要你做了,就有分了,谢谢大家帮忙了
- 菜鸟DateTimePicker的问题?
- 请兄弟们给估个价钱,我自己接的私活
- 那为大虾有Delphi对 SQL SERVER数据库数据备份还原的代码,可以告之,不尽感谢,高分酬谢?
- 如何用Installshield 打包Web应用程序
- 本站持续开通了编程书藉下载并且新增大软件下载及电影下载,有兴趣的进来看看
- 如何同一个按扭打印memo的内容??
- 我做了一张很死的报表,要求把查询得到的数据的都打印出来,请问怎么增加相同格式的页面,而且怎样选择打印纸张大小,选择后我的表格还是
- 关于小数的几个问题。(ngyxh)
- 一个简单问题
- 怎样在实现IE状态栏里的那个进度条?或是有没有这方面的控件?
begin
if (checkbox[i] as CheckBox).checked=true then;//这里如何写
begin
(label[i] as Label).caption:='0';//这里如何写
end;
end;
begin
if TCheckBox(self.FindComponent('checkbox'+inttostr(i))).Checked=true then
.....
end;
begin
if pos('checkbox',form1.controls[i].name)>0 and (form1.controls[i] is TCheckBox) then
if (form1.controls[i] as TCheckBox).checked then
begin
for j:=0 to Form1.controlCount-1 do
begin
if pos('Label',form1.controls[i].name)>0 and (form1.controls[i] is TLabel) then
(form1.controls[j] as TLabel).Caption:='0'
end;
end;
end;
如果没有就可以用 xwc21s() 的方法;
没有的话就要判断是否是你要改变的;
var i : integer;
begin for i:=0 to form1.componentcount -1 do begin
if (form1.Components[i] is TCheckBox) then begin
if TCheckBox(form1.Components[i]).Checked then
TLabel(form1.FindComponent('Label'+Copy((form1.Components[i]).Name,Length((form1.Components[i]).Name),1))).Caption := 'OK';
// showmessage(Copy((form1.Components[i]).Name,Length((form1.Components[i]).Name)-1,1)+(form1.Components[i]).Name);
end;
end;
end;//要保证checkbox和label的标号一致哦,
begin
if (findcomponents('CheckBox'+inttostr(i)) as TCheckBox).checked then
(findcomponents('Label'+inttostr(i)) as TLabel).Caption:='0';
end;
i: integer
begin
for I:= 0 to 5 do
begin
if (findcomponents('CheckBox'+inttostr(i)) as TCheckBox).checked then
(findcomponents('Label'+inttostr(i)) as TLabel).Caption:=inttostr(i);
end;
end;
你的代码我试过,不行.
我试过这样,也不行
var
vComponent,vComponent1: TComponent;begin
for I := 1 to 15 do
begin
vComponent := FindComponent('CheckBox' + IntToStr(I));
vComponent1 := FindComponent('label' + IntToStr(I));
if Assigned(vComponent) then
if TCheckBox(vComponent).checked = true then
if Assigned(vComponent1) then
Tlabel(vComponent1).caption := '1';
end;
end;还望大家指出
Black(小熊)的方法最好。应该得100分:)
你的方法已经可以了,不过为什么这样的代码不行呢?
var
i: integer;
begin
for I:= 0 to 5 do
begin
if (findcomponents('CheckBox'+inttostr(i)) as TCheckBox).checked then
(findcomponents('Label'+inttostr(i)) as TLabel).Caption:=inttostr(i);
end;
end;
你的方法也可以,而且比 yansea(思宏)的要好一些
yansea(思宏)的方法是如果checkbox6,和label6的话,也是一样了!