发现用showmodal直接显示窗口,close后不能释放资源。比如窗体中
的Tedit中输入了字符,那么下次showmodal字符还在。我要怎么做啊?

解决方案 »

  1.   

    因为Close后没有释放。请参阅以下代码:
    var MyModalForm:TMyModalForm;
    begin
      MyModalForm:=TMyModalForm.Create(Application);
      if MyModalForm.ShowModal=mrOk then
        begin
        end;
      MyModalForm.Free;
    end;
    这样就可以了。
      

  2.   

    如 XXX.ShowModal;
    下面加一句
    XXX.close;
    FreeAndNil(XXX);但下次進去要重新創建!!
      

  3.   

    按楼上两位的做法,我在close事件中加入了代码,但是关闭时会出错。
      

  4.   

    这样也行的:
    begin
     form:=TForm.Create(self);
     with form do
     try
       ShowModal;
     finally
       free;
     end;
    end;
      

  5.   

    我在colse事件加入
    action := cafree;
    form2 := nil;
    下一此打开窗体时出现错误信息
    project project.exe raised exception class EAccessViolation with message'Access violation at address 0044F1FB in module 'project1.exe'.Read of address 00000000'.Process stopped.Use Step or Run to continue.
      

  6.   

    如果要Free,下次使用就必须自己创建。也就是每次用的时候创建,用完就释放。请参看我的最初回答。
      

  7.   

    你在fromshow的時候把edit都初始化
    if component is Tedit then
       (component as Tedit ).clear;
      

  8.   

    将窗体实例清空
    freeandnil(对象);
      

  9.   

    在fromshow的時候把edit都初始化
      

  10.   

    "我在colse事件加入
    action := cafree;
    form2 := nil;"
    action := cafree;
    已经把form2释放了,再给form2赋值当然出错.
      

  11.   

    释放以后如果还要显示这个窗口,那么就用:
    form2 := Tform2.create(self);
      

  12.   

    if not Assigned(form2) then
       form2:=TForm2.Create(self);
    try
       form2.showmodal;finally
      FreeAndNil(form2);
    end;