问题
动态创建的VCL控件如何改变属性?例如
procedure StartForm.ShowLabel(Top,Left,Width,Height: Integer;
Caption,Name: String;Parent: TForm;Color,FontColor: TColor);
var
  LoadLabel: TLabel;
begin
  LoadLabel := TLabel.Create(Parent);
  LoadLabel.Parent := Parent;
  LoadLabel.AutoSize := False;
  LoadLabel.Caption := Caption;
  LoadLabel.Name := Name;
  LoadLabel.Top := Top;
  LoadLabel.Left := Left;
  LoadLabel.Width := Width;
  LoadLabel.Height := Height;
  LoadLabel.Color := Color;
  LoadLabel.Font.Color := FontColor;
  //LoadLabel.Font.Size := 1;
  //LoadLabel.Transparent := True;
end;现在我想改变LoadLabel的Width属性,如何进行更改?

解决方案 »

  1.   

    并且这两句改为:
      LoadLabel := TLabel.Create(self);
      LoadLabel.Parent := self;
      

  2.   

    楼上的错了我这里是一个创建label的函数
    想在函数已经创建后
    再修改他的属性
    如调用:ShowLabel(100,100,100,10,'a','b',ShowForm,clBlue,clBlue);
    会在ShowForm上加一个离Form Top,Left分别为100,宽为100,高为10,名字为'b'...等的Label组件
    现在我现想再改Width为150怎么改?
      

  3.   

    LoadLabel.Width :=150;这样不行么?
      

  4.   

    因为名字是动态的,所以用findComponent找到Label,然后再进行修改...
      

  5.   

    因为名字是动态的,所以用findComponent找到Label,然后再进行修改...
      

  6.   

    procedure TForm1.Button1Click(Sender: TObject);
    var tempLabel:TLabel;
    begin
        tempLabel:=TLabel.Create(self);
        tempLabel.Parent:=Self;
        tempLabel.Caption:='haha';
        tempLabel.Name:='aa';
        tempLabel.Left:=100;
        tempLabel.Top:=100;
    end;procedure TForm1.Button2Click(Sender: TObject);
    begin
        (self.FindComponent('aa') as TLabel).Caption:='xixi';
    end;