+ -
当前位置:首页 → 问答吧 → 一个关于指针的问题,请教大家。

一个关于指针的问题,请教大家。

时间:2011-08-24

来源:互联网

比如说一个窗体中有四个Label:Label1..Label4.
我想给他们的Text属性分别赋值为1,2,3,4,能不能用for语句?

我希望能这样:
const
  Labels: Array[0..3] of ^Label =(@Label1,@Label2,@Label3,@Label4);
begin
  for i:=0 to 3 do Labels[I]^.text:= inttostr(i);
end;
但是不能通过编译,请高手帮忙改下,或者有别的办法,先谢了!

作者: cggong   发布时间: 2011-08-24

var
  _Label:TLabel;
  i:integer;
begin
For i:=1 to 4 do 
if FindComponent('Label'+inttostr(I)) <> nil then
begin
  _Label:=FindComponent('Label'+inttostr(I))as TLabel;
  _Label.Text:=inttostr(i);
end;
end;

作者: nana20082009abc   发布时间: 2011-08-24

var
  i,c: integer;
begin
  c:=1;
  for i := 0 to self.ComponentCount - 1 do
  begin
  if self.Components[i] is TLabel then
  (self.Components[i] as TLabel).Caption := inttostr(c);
  inc(c);
  end;
end;

作者: jdbca   发布时间: 2011-08-24

热门下载

更多