var
i: integer;
begin
for I := 1 to query1.recordcount do
TCheckbox(FindComponent('Checkbox'+IntToStr(I))).Caption:=IntToStr(I);
end;
i: integer;
begin
for I := 1 to query1.recordcount do
TCheckbox(FindComponent('Checkbox'+IntToStr(I))).Caption:=IntToStr(I);
end;
1. FindComponent要通过CheckBox的Owner来调用
如: CheckBox的Owner为Form, 则Form.FindComponent() 若为Pannel,则用Pannel.FindComponent()2.不要直接写
TCheckbox(FindComponent('Checkbox'+IntToStr(I))).Caption:=IntToStr(I); 因为FindComponent()有返回值可能是Nil, 那时,这要写就肯定会出异常了! 可改为;
aCheckBox := TCheckbox(FindComponent('Checkbox'+IntToStr(I)));
if aCheckBox <> nil then aCheckBox.Caption := '你要写的值'注意这两点,应该就没什么问题了!
建议使用 MyCheckbox.Tag 将他们分别设为 ID,
for i<ComponentCount
begin
aCheckBox = aCheckBox := TCheckbox(Components[i]);
if aCheckBox <> nil then begin
if aCheckBox.tag=ID then aCheckBox.Caption="...";
end
end
i: integer;
a: tcomponent;
begin
for I := 1 to query1.recordcount do
a:=FindComponent('Checkbox'+IntToStr(I))
a.Caption:=IntToStr(I);
end;
i: integer;
a: tcomponent;
begin
for I := 1 to query1.recordcount do
begin
a:=FindComponent('Checkbox'+IntToStr(I))
a.Caption:=IntToStr(I);
end;
end;
经典!