gpt4 book ai didi

delphi - 如何在主窗体之前显示用于设置配置的窗体?

转载 作者:行者123 更新时间:2023-12-03 18:17:06 25 4
gpt4 key购买 nike

在我的项目中我有两个表单(form1,form2),form1是配置表单。

我想显示 Form1,当我们单击 Button1 时,然后显示 Form2 和释放(释放)Form1。我该怎么做?

我使用这个代码。但是这个项目启动然后自动退出。一位 friend 说,因为应用程序消息循环从未启动,应用程序终止,因为主窗体不存在。我该如何解决这个问题?

uses Unit2;

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
Application.CreateForm(TForm2, Form2);
Release;
end;

///

program Project1;
uses
Forms,
Unit1 in 'Unit1.pas' {Form1},
Unit2 in 'Unit2.pas' {Form2};
{$R *.res}
begin
Application.Initialize;
Application.MainFormOnTaskbar := True;
Form1:= TForm1.Create(Application);
Application.Run;
end.

最佳答案

完全按照您在问题标题中的要求进行操作:创建并显示配置表单,然后创建并显示主表单。诀窍在于您如何创建它们。 Only use Application.CreateForm for the one form that you want to be your main form.对所有其他形式使用普通对象创建技术。

像这样修改您的 DPR 文件:

var
ConfigForm: TConfigForm;
begin
Application.Initialize;

ConfigForm := TConfigForm.Create(nil);
try
if ConfigForm.ShowModal <> mrOK then
exit;
finally
ConfigForm.Free;
end;

Application.CreateForm(TMainForm, MainForm);
Application.Run;
end.

关于delphi - 如何在主窗体之前显示用于设置配置的窗体?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4629916/

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