var
I: Integer;
begin
for I := 1 to 100 do
if FindComponent(Format('Edit%d', [I])) is TEdit then
(FindComponent(Format('Edit%d', [I])) as TEdit).Text := '这是比较简单的一种方法';
end;
I: Integer;
begin
for I := 1 to 100 do
if FindComponent(Format('Edit%d', [I])) is TEdit then
(FindComponent(Format('Edit%d', [I])) as TEdit).Text := '这是比较简单的一种方法';
end;
for i := 1 to 100
Test[i] := Tedit.create(self);
通过数组test[i]来操作.
begin
if (self.Controls[i]) is tedit then
(self.Controls[i] as tedit).Text :='1';
end;
begin
for i:=1 to 100 do
if (FindComponent('Edit'+IntToStr(i) is TEdit) then
(FindComponent('Edit'+IntToStr(i) as TEdit).text:='';
end;
for i := 1 to 100
Test[i] := Tedit.create(self);
通过数组test[i]来操作.
那 控件的 TAG 属性是做什么用途????????、
例如你的100个Edit各有各的名字,而不是有规律的。你可以将同类的tag全都设为1,另一类的全都设为2,另一类....,你可以只将其中的某一类或几类或全部一起操作
var i:integer;
begin
for i:=1 to self.ComponentCount-1 do
if (self.Components[i] is TEdit) then
if (self.Components[i] as TEdit).tag=1 then
(self.Components[i] as TEdit).text:='My tag is 1';
end;
var
// 定义动态数组
MyArray: Array of TEdit; //在初始化的时候可以这样做
var
i, j: Integer;
begin
//检查符合条件的Edit的个数
j:= 0;
for i:= 0 to self.ComponentCount - 1 do
begin
if (self.Components[i] is TEdit) then
j:= j + 1;
end;
//设置动态数组的长度
SetLength(MyArray, j);
j:= 0;
//为动态数组赋值
for i:= 0 to self.ComponentCount - 1 do
begin
if (self.Components[i] is TEdit) then
begin
MyArray[j]:= (self.Components[i] as TEdit);
j:= j + 1;
end;
end;
end;
这样你就已经将所有的TEdit作为元素写入数组中了,以后的问题就是你将如何去使用该数组了,如果你使用了tag的话,可以将上面的“if (self.Components[i] is TEdit) then”改写为“if self.Components[i].tag = 你要求的数值 then”,这样就可以将所有符合条件的控件作为元素写入数组中了,以上内容仅供参考,呵呵