0
votes

I have a delphi application where the main form is a login form - this contains various database and user objects necessary for the program. Once the user logs in, I hide this form and open another.

My issue is, how do I cause the application to minimize when the child form is minimized? I figured out how to restore the child when the main is restored using windows messages, but I can't figure out how to get the app to minimize so when they click on the taskbar they only have to click once - not once to minimize and then again to restore.

Any help is appreciated - I was trying to use the NCACTIVATE - but that causes endless loops in some cases with print dialogs and other windows...

Thanks, Christy

3

3 Answers

3
votes

The best way I have found is a slight change in architecture. You don't want your login form to be your application's main form. You can fix this two different ways, but since you are maintaining your database controls on your login form then I think this is the ideal way.

  1. Choose a different form to be your main form and set it up to be created first.
  2. In your DPR, create your login form manually with loginForm := TLoginForm.Create(nil) instead of using Application.CreateForm.
  3. Show the login form before your Application.Run. When you are done with it just hide it instead of freeing it.

Ideally you should move all the database components into a DataModule so you can free your LoginForm once login is complete.

2
votes

Why not make the main form the existing child form, put the database logic in a data module, and create and handle the login form manually? This is the pattern that I generally use:

Create a datamodule which will be auto-created FIRST in the list (before the main form). Tee datamodule in the OnCreate will initialize the database and display a login form which is NOT in the auto-create list, and is created and handled entirely in the datamodule. If I need a splash screen, then the datamodule also provides that functionality in the same manner.

The mainform OnCreate checks to insure that the user logged in successfully, if not then calls application.terminate;

0
votes

i use TMinModal to minimize my app when a non-main form is minimized.

http://vvv.truls.org/pascal/Units.Delphi/UI/MinModal.pas