gpt4 book ai didi

delphi - 如何在MainForm之前创建一个表单?

转载 作者:行者123 更新时间:2023-12-03 14:56:37 24 4
gpt4 key购买 nike

我想创建一个启动屏幕(在主窗体之前),该屏幕将显示 x 秒,但我不想延迟主窗体的创建 x 秒。

因此,我创建启动屏幕表单,创建主表单,然后在 x 秒后关闭启动屏幕表单。
据我了解,用 CreateForm 创建的第一个表单是主表单。这是正确的吗?

begin
Application.Initialize;
Application.MainFormOnTaskbar := FALSE;
Application.Title := AppName;
frmSplash:= TfrmSplash.Create(NIL); <----- not main form??
Application.CreateForm(TfrmMain, frmMain); <----- main form??
frmMain.LateInitialization;
frmMain.show;
Application.Run;
end.

关闭启动窗体
启动画面有一个 TTimer。计时器在启动窗体中执行一些动画,并在 x 秒后关闭窗体:

procedure TfrmSplash.CloseSplashForm;
begin
Timer.Enabled:= FALSE;
Close; <-- I do see the program reaching this point
end;

但是,应用程序在关闭时泄漏内存:

5 - 12 bytes: TMoveArrayManager<System.Classes.TComponent> x 4, Unknown x 2
13 - 20 bytes: TObservers x 1, TList x 3, Unknown x 3
21 - 36 bytes: TComponent.GetObservers$942$ActRec x 1, TPen x 2, TIconImage x 1, TPadding x 1, TBrush x 3, TTouchManager x 2, TMargins x 2, TSizeConstraints x 2, TList<System.Classes.TComponent> x 4, UnicodeString x 3, Unknown x 6
37 - 52 bytes: TDictionary<System.Integer,System.Classes.IInterfaceList> x 1, TPicture x 1, TGlassFrame x 1, TFont x 4
53 - 68 bytes: TIcon x 1
69 - 84 bytes: TControlScrollBar x 2
85 - 100 bytes: TTimer x 1
101 - 116 bytes: TControlCanvas x 2
149 - 164 bytes: Unknown x 2
437 - 484 bytes: TImage x 1
917 - 1012 bytes: TfrmSplash x 1

看起来 frmSplash 实际上并未被释放。

最佳答案

向启动窗体添加一个OnClose事件并设置

Action := caFree;

关于delphi - 如何在MainForm之前创建一个表单?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45611162/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com