运行时如何生成一个可视控件,比如TEdit 控件,小弟想了很久,求解

解决方案 »

  1.   

    (转载!)
    .在Form的Public中定义TEdit控件
      Edit1:TEdit;
    2.在需要生成的地方加入以下代码:
      Edit1:=TEdit.Create(Self);
      Edit1.Parent:=Form1;
      Edit1.Left ?:=20;
      Edit1.Top :=20;
      Edit1.Text :=’Edit1 Text’;
    3.使用完毕后,释放分配的资源
      if? Assigned(Edit1) then Edit1.Free; ?
    ㈡、运行时生成非可视控件:以下以 TTimer控件为例
    1.在Form的Public中定义TTimert控件
      Timer1:TTimber;
    2.在需要生成的地方加入以下代码:
      Timer1:=TTimer.Create(Self); 
      Timer1.OnTimer:=YourAction;
    YourAction是自己定义的OnTimer事件,使用
    procedure TForm1.YourAction(Sender:TObject); 完成
    3.使用完毕后,释放分配的资源 
      if? Assigned(Timer1) then Timer1.Free; ?