Board index » delphi » Terminating an Application prior to creating a Main Form

Terminating an Application prior to creating a Main Form

Hi,

I have a Login Form which I want to open to allow me to verify if the user is valid.  I want to open it before the MAIN FORM (MDI Form) is open.  This Login form can either accept or not to accept the user depending if his/her login is valid (e.g. Cancel Log is selected or thrice entered a wrong password/user id).  Below are the sample codes:

begin
   ...
   Application.Initialize;

   with TfrmAppUser.Create(nil) do  //Login Form that ask for User ID and Password of the user
   begin
      if Login = 1 then   //1 means login failed
      begin
         Application.Terminate;
         Halt (1);
         Exit;
      end;
      ...
   end;

   ...
   Application.CreateForm(TfrmSBOSS, frmSBOSS);
   Application.CreateForm(TdmTranslation, dmTranslation);

   Application.Run;

end.

Based on the codes, once the Login returns 1 (indicating a cancel in login), I'm encountering an access violation in User32DLL. What seems to be the problem? Is there other way of effecting this kind of feature?

Alll the best.

Jimar

 

Re:Terminating an Application prior to creating a Main Form


This may be of help:

begin
  Application.Initialize;

  with TfrmAppUser.Create(nil) do  //Login Form that ask for User ID and
Password of the user
    begin
      if Login <> 1 then   //1 means login failed
        begin
          Application.CreateForm(TfrmSBOSS, frmSBOSS);
          Application.CreateForm(TdmTranslation, dmTranslation);
          Application.Run;
        end
      else
        // show a message if you like.
    end;
end.

I can't see myself ever using Halt for anything.

ShaneB

Re:Terminating an Application prior to creating a Main Form


this is how I do it :

  Application.Initialize;
  Application.CreateForm(TfmPassword, fmPassword);

  if fmPassword.ShowModal = mrOK then begin
    fmPassword.Free;
    Application.CreateForm(TfmMain, fmMain);
    Application.Run;
  end
  else
    Application.Terminate;

Re:Terminating an Application prior to creating a Main Form


I use a similar system with my programs.

I actually call the login from the Main Form Create procedure.
IsAllowedAccess is set by the login form.

frmLogin := TfrmLogin.Create(Self);
frmLogin.ShowModal;
if Is AllowedAccess then
begin
  {continue processing}
end else begin
  PostMessage(Self.Handle, WM_CLOSE, 0, 0);
end;

Quote
"jimar jaafar" <jimar_jaa...@abacusph.com> wrote in message

news:3c3d6439$1_2@dnews...
Quote

> Hi,

> I have a Login Form which I want to open to allow me to verify if the user

is valid.  I want to open it before the MAIN FORM (MDI Form) is open.  This
Login form can either accept or not to accept the user depending if his/her
login is valid (e.g. Cancel Log is selected or thrice entered a wrong
password/user id).  Below are the sample codes:
Quote

> begin
>    ...
>    Application.Initialize;

>    with TfrmAppUser.Create(nil) do  //Login Form that ask for User ID and

Password of the user
Quote
>    begin
>       if Login = 1 then   //1 means login failed
>       begin
>          Application.Terminate;
>          Halt (1);
>          Exit;
>       end;
>       ...
>    end;

>    ...
>    Application.CreateForm(TfrmSBOSS, frmSBOSS);
>    Application.CreateForm(TdmTranslation, dmTranslation);

>    Application.Run;

> end.

> Based on the codes, once the Login returns 1 (indicating a cancel in

login), I'm encountering an access violation in User32DLL. What seems to be
the problem? Is there other way of effecting this kind of feature?

- Show quoted text -

Quote

> Alll the best.

> Jimar

Other Threads