Search code examples
delphiauthenticationtform

How to close a window without closing the whole program?


in my application i have two forms let's say, LoginForm and AccountForm

The LoginForm is set as the main Form, it is the form when the user is able to login from to his account ( two TEdits and login Button ). When a user type his login details and connect, a new form which is AccountForm is opened.

How to close the LoginForm on login success without closing the whole application? or in such language how to use the code below to close the Login form only but not the application.

if (not IncludeForm.sqlquery1.IsEmpty) and (isblacklisted='0') and (isactivated='1')  then
begin // Login Successful *** Show the account window
AccountForm.Show;
LoginFrom.Close; // <----The problem is in this line, using this line causes the whole application to close***}
end;

Thankyou


Solution

  • You can fetch here the source code of the excellent article Display a LogIn / Password Dialog Before the Main Form is Created by Zarko Gajic .

    Excerpt:

    program PasswordApp;
    
    uses
      Forms,
      main in 'main.pas' {MainForm},
      login in 'login.pas' {LoginForm};
    
    {$R *.res}
    
    begin
      if TLoginForm.Execute then
      begin
        Application.Initialize;
        Application.CreateForm(TMainForm, MainForm) ;
        Application.Run;
      end
      else
      begin
        Application.MessageBox('You are not authorized to use the application. The password is "delphi".', 'Password Protected Delphi application') ;
      end;
    end.