var
i: integer;
a: tcomponent;
begin
for I := 1 to query1.recordcount do
begin
a:=FindComponent('Checkbox'+IntToStr(I))
a.Caption:=IntToStr(I);
end;
end;
名字设为 “Checkbox”+IntToStr(i) 不好。名字还是设为你想要的名字。
建议使用 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