delphi – 动态表单创建
发布时间:2020-12-15 04:12:11 所属栏目:大数据 来源:网络整理
导读:我在运行时创建我的表单,如下所示: AboutForm := TAboutForm.Create(AboutForm);try AboutForm.ShowModal;finally AboutForm.Free;end; 但是使用其中任何一个有什么区别: AboutForm := TAboutForm.Create(Self);AboutForm := TAboutForm.Create(nil);About
我在运行时创建我的表单,如下所示:
AboutForm := TAboutForm.Create(AboutForm); try AboutForm.ShowModal; finally AboutForm.Free; end; 但是使用其中任何一个有什么区别: AboutForm := TAboutForm.Create(Self); AboutForm := TAboutForm.Create(nil); AboutForm := TAboutForm.Create(Application); 它们似乎从我能看到的都是一样的但是正确的,或者它们都是正确的,这通常是最好用的? 感谢您的评论谢谢:) 解决方法
TForm.Create将所有者作为参数.
在您的第一个示例中,AboutForm是所有者.这显然是一个坏主意,因为它尚未创建. 当Self是参数时,进行调用的实例是所有者. 当您传入所有者时,实际上您不需要明确地释放我.当所有者被释放时,所有者将释放它. 这就是你的代码应该是这样的: AboutForm := TAboutForm.Create(nil); try AboutForm.ShowModal; finally AboutForm.Free; end; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |