如何在主表单之前显示用于设置配置的表单? [英] How can I display a form for set configuration before the main form?
问题描述
在我的项目中,我有两个表单(form1,form2),form1是配置表单。
我想显示Form1,当我们单击Button1然后显示Form2和免费(发布)Form1。我该怎么做?
我使用此代码。但该项目会启动,然后自动退出。一位朋友说,因为应用程序消息循环永远不会启动,并且应用程序因主窗体不存在而终止。我该如何解决这个问题?
使用Unit2;
{$ R * .dfm}
过程TForm1.Button1Click(Sender:TObject);
开始
Application.CreateForm(TForm2,Form2);
发布;
结尾;
///
计划Project1;
使用
表格,在 Unit1.pas {Form1}中使用
Unit1,在 Unit2.pas {Form2}中使用
Unit2;
{$ R * .res}
开始
Application.Initialize;
Application.MainFormOnTaskbar:=真;
Form1:= TForm1.Create(应用程序);
Application.Run;
结尾。
完全按照问题标题中的要求进行操作:创建并显示配置表单,然后创建并显示主表单。诀窍在于您如何创建它们。 仅对一种形式使用 Application.CreateForm
像这样修改DPR文件:
var
ConfigForm:TConfigForm;
开始
应用程序。
ConfigForm:= TConfigForm.Create(nil);
如果ConfigForm.ShowModal<> ;,请尝试
mrOK然后
退出;
最终
ConfigForm.Free;
结尾;
Application.CreateForm(TMainForm,MainForm);
Application.Run;
结尾。
in my project i have two form's(form1,form2), form1 is configuration form.
i want to show Form1 and when we click Button1 then show Form2 and free(Release) Form1. how can to i do this?
i use this code. but this project start and then exit automatically.A Friend said because the application message loop never start, and application terminates because main form does not exist. how i can to solve this problem?
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.
Do exactly what you asked in the question title: Create and show the configuration form, and then create and show the main form. The trick is in how you create them. Only use Application.CreateForm
for the one form that you want to be your main form. Use the ordinary object creation technique for all other forms.
Modify your DPR file like so:
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.
这篇关于如何在主表单之前显示用于设置配置的表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!