This is * .dpr:
program Project1; uses Vcl.Forms, Unit1 in 'Unit1.pas' {Form1}, Unit2 in 'Unit2.pas' {Form2}; {$R *.res} var MainForm: TForm1; begin Application.Initialize; Application.MainFormOnTaskbar := True; Application.CreateForm(TForm1, Form1); Login; Application.Run; end.
Login form:
unit Unit2; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls; type TForm2 = class(TForm) Button1: TButton; private { Private declarations } public { Public declarations } end; var Form2: TForm2; procedure Login; implementation {$R *.dfm} Uses Unit1; procedure Login; begin with TForm2.Create(nil) do try Application.MainForm.Hide; if ShowModal = mrOK then Application.MainForm.Show else Application.Terminate; finally Free; end; end; end.
Basic form:
unit Unit1; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls; type TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} Uses Unit2; procedure TForm1.Button1Click(Sender: TObject); begin Login; end; end.
Both buttons are installed in Modal: mrOK. The login form is not automatically created, but in the list of available forms.
The problem is this: If you close the login form (without pressing a button) within the second second, the Main form is displayed, and then it closes (and, of course, the application closes). It happens very fast. It seems to flicker.
How can I cancel this attempt of my main form in order to try to show it when I close the login form?
In addition, the installation:
Application.MainFormOnTaskbar := False;
Does not help...