findcomponent判断是否存在
free释放

解决方案 »

  1.   

    运行时生成可视控件:以下以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; ?
      

  2.   

    if Assigned(MyButton) then
    begin
      MyButton.Free;
      MyButton := nil;
    end;// 或
    FreeAndNil(MyButton);