首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

初学者级有关问题——关于form的Release

2012-03-22 
菜鸟级问题——关于form的Releaseforms有两种类型,Auto-create forms和Available forms。我在这两个forms 分

菜鸟级问题——关于form的Release
forms有两种类型,Auto-create forms和Available forms。我在这两个forms 分别加了2个关闭按钮。
Available forms类型中的关闭按钮,需要加上form.Release来释放form占用的内存,问题:Auto-create forms类型的forms里的关闭按钮需要加form.Release才能释放form占用的内存么?

代码
procedure TForm1.Button2Click(Sender: TObject);
begin
  form1.Close;//form1为Auto-create forms
  form1.Release;//虽然加上这句系统不会出错,但这句需要加么?如果不加在关闭程序的时候Auto-create forms会不会自动释放form占用的内存?
end;

procedure TForm2.Button1Click(Sender: TObject);
begin
  form2.Close;//form2为Available forms
  form2.Release;//必须得加上,要不不能释放动态创建的form所占的内存。
end;

本人菜鸟,谢谢各位大侠!

[解决办法]
Close 即可以释放掉Form占用的内存, 可以参看 VCL 源码:
procedure TCustomForm.Close;
var
CloseAction: TCloseAction;
begin
if fsModal in FFormState then
ModalResult := mrCancel
else
if CloseQuery then
begin
if FormStyle = fsMDIChild then
if biMinimize in BorderIcons then
CloseAction := caMinimize else
CloseAction := caNone
else
CloseAction := caHide;
DoClose(CloseAction);
if CloseAction <> caNone then
if Application.MainForm = Self then Application.Terminate
else if CloseAction = caHide then Hide
else if CloseAction = caMinimize then WindowState := wsMinimized
else Release;
end;
end;

热点排行