因为Close后没有释放。请参阅以下代码: var MyModalForm:TMyModalForm; begin MyModalForm:=TMyModalForm.Create(Application); if MyModalForm.ShowModal=mrOk then begin end; MyModalForm.Free; end; 这样就可以了。
这样也行的: begin form:=TForm.Create(self); with form do try ShowModal; finally free; end; end;
我在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.
如果要Free,下次使用就必须自己创建。也就是每次用的时候创建,用完就释放。请参看我的最初回答。
你在fromshow的時候把edit都初始化 if component is Tedit then (component as Tedit ).clear;
var MyModalForm:TMyModalForm;
begin
MyModalForm:=TMyModalForm.Create(Application);
if MyModalForm.ShowModal=mrOk then
begin
end;
MyModalForm.Free;
end;
这样就可以了。
下面加一句
XXX.close;
FreeAndNil(XXX);但下次進去要重新創建!!
begin
form:=TForm.Create(self);
with form do
try
ShowModal;
finally
free;
end;
end;
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.
if component is Tedit then
(component as Tedit ).clear;
freeandnil(对象);
action := cafree;
form2 := nil;"
action := cafree;
已经把form2释放了,再给form2赋值当然出错.
form2 := Tform2.create(self);
form2:=TForm2.Create(self);
try
form2.showmodal;finally
FreeAndNil(form2);
end;