我现在有30个组件,都是TLabel,但是全部都被我重命名了。我把30个TLabel分成两组,分别是 A1、A2、A3……A15 和 B1、B2、B3……B15,
我现在想要对这30个TLabel的Caption属性进行赋值,请问循环语句如何写?如果可以,请尽量使用For语句,代码力求简洁,有些地方最好附上注释,菜鸟我感激不尽!!
我现在想要对这30个TLabel的Caption属性进行赋值,请问循环语句如何写?如果可以,请尽量使用For语句,代码力求简洁,有些地方最好附上注释,菜鸟我感激不尽!!
if Self.Componets[m] is TLabel then
TLabel(Self.Componets[m]).Caption:='都是一个名字';
//其他的自己想象一下~~~比如
TLabel(Self.Componets[m]).top
TLabel(Self.Componets[m]).left 等等,反正你想改啥就改啥
[错误] Unit2.pas(268): Undeclared identifier: 'Componets'
[错误] Unit2.pas(268): Operator not applicable to this operand type
[错误] Unit2.pas(269): Undeclared identifier: 'Componets'
var
I: Integer;
Button: TControl;
begin
for I := 0 to ControlCount - 1 do
begin
Button := nil;
Button := FindChildControl('A' + IntToStr(I));
if Assigned(Button) then
TLabel(Button).Caption := 'Label' + IntToStr(I);
end;
end;
var
I: Integer;
Button: TComponent;
begin
for I := 0 to 20 do
begin
Button := nil;
Button := FindComponent('A' + IntToStr(I));
if Assigned(Button) then
TLabel(Button).Caption := 'Label' + IntToStr(I);
end;
end;开始写错了。 FindChildControl只是TWINCONTROL继承下来的控件的查找
是一个窗口记录属于他的控件列表Assigned(button)
是如果button是存在的