假设我有很多相同的控件如50个EDIT控件,
控件名称分别为EDIT1,EDIT2,EDIT3,EDIT4....EDIT50
现在我要给控件赋值,不想写50行赋值语句
怎么用循环语句赋值呢
如这样:
for i:=1 to 50 do
edit[i].text:=array[i];
//这句是错的,那位大侠知道如何写循环
控件名称分别为EDIT1,EDIT2,EDIT3,EDIT4....EDIT50
现在我要给控件赋值,不想写50行赋值语句
怎么用循环语句赋值呢
如这样:
for i:=1 to 50 do
edit[i].text:=array[i];
//这句是错的,那位大侠知道如何写循环
j: integer;
begin
j :=0;
for i:=0 to componentcount-1 do
begin
if components[i] is tedit then
begin
(components[i] as tedit).text = ary[i];
j := j+1;
end;
end;
end;
begin
if Components[i] is TEdit then
TEdit(Components[i]).Text := Array[i];
end;
j: integer;
begin
j :=0;
for i:=0 to componentcount-1 do
begin
if components[i] is tedit then
begin
(components[i] as tedit).text = ary[i];
j := j+1;
end;
end;
end;
if Components[iCount] is TEdit then
TEdit(Components[iCount]).Text:='';
begin
IF ( Components[I] is TEdit ) then
begin
(Components[I] as TEdit).Text := array[J];
J:=J+1;
end;
end;
begin
IF ( Components[I] is TEdit ) then (Components[I] as TEdit).Text := array[J];
end;
我也是用你那种方法实现某个功能 ,
但是如果有其它控件(尤其是无焦点)的干扰,
就会报错的,好不容易搞个几个Try 才算搞掂,
但,这理论确实是可行的。
for i := 0 to ComponentCount - 1 do
begin
edit[i]:=Tedit.create(application);
edit[i].Text := Array[i];
edit[i].name:=intstr(i);
edit[i].bouds:=??
edit[i].true:=true;
end;
TEdit *Edit
for(int i=1; i<=componentcount; i++){
Edit = dynamic_cast<TLabelEffect*>(
FindComponent("Edit"+IntToStr(i)));
if (Edit!= NULL)
{Edit->Text.c_str=array[i];
}
在DELPHI的每一个VCL组件中都有个属性:COPONENTINDEX;利用这个就实现控件数组:
PROCEDUER TFORM1.BUTTON1(SENDER:TOBJECT);
VAR INDEX:INTEGER
BEGIN
FOR INDEX:=0 TO CONTROLCOUNT-1 DO
BEGIN
IF COMPONENTS[INDEX] IS TEDIT THEN
BEGIN
(COMPONENTS[INDEX] AS TEDIT).COLOR := C1LIME;
END;
END;
END;PROCEDUER TFORM1.EDIT1ENTER(SENDER:TOBJECT);
BEGIN
//得焦点时改背景为YELLOW
(SENDER AS TEDIT).COLOR := C1YELLOW;
END;PROCEDUER TFORM1.EDIT1EXIT(SENDER:TOBJECT);
BEGIN
//失焦点时改背景为白
(SENDER AS TEDIT).COLOR := C1WHITE;
END;-------------------------------------
begin
if Panel1.Controls[i].ClassNameIs('TEdit') then
TEdit(Panel1.Controls[i]).Text:=...;
end;