tags:

views:

413

answers:

3

Hi all, 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  A: 

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.

Jim McKeeth
Just to complicate it a little more:I am using a data module - all of my query objects are on the data module. I am also using a mySql server object add in that seems to have some quirks - the database connection is done on the fly in code depending on whether we are running in production or test so I had to put the MyConnection object on the login form and then relink all of the queries in the onshow event.. I will try the suggestion above though and let you know if it works...
This is my current dpr - I have a splash screen that checks for an update on an ftp server first:
Application.Initialize; Application.Title := 'SnoGem Quoting System'; Application.CreateForm(TFLogin, FLogin); FLogin.FLog.AddLog('applicationterminate: ' + VarToStr(FLogin.ApplicationTerminate)); if Not(FLogin.ApplicationTerminate) then begin Application.CreateForm(Tdm, dm); Application.CreateForm(TFSplashScreen, FSplashScreen); Application.CreateForm(TFMain, FMain); Application.CreateForm(TFUserMgr, FUserMgr); Application.CreateForm(TFAddComment, FAddComment);
Application.CreateForm(TFAddContact, FAddContact); Application.CreateForm(TFAddCompany, FAddCompany); Application.CreateForm(TFAddEditQuote, FAddEditQuote); Application.CreateForm(TFAddActivity, FAddActivity); Application.CreateForm(TFPrintDlg, FPrintDlg); Application.CreateForm(TFActivityDate, FActivityDate); FSplashScreen.ShowModal; end; Application.Run;
Update your question with the details, or ask a new question. The way it is formatted makes it hard for me to follow it.
Jim McKeeth
+2  A: 

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;

skamradt
A: 

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

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

X-Ray
Is there a restriction on the main form being hidden? I tried to use this but if the main form is hidden, it did not minimize the app. When I used Windows Messages to minimize the app, it does not restore anything when the task bar is clicked...Thanks for the suggestion
WooHoo - this works - at least well enough - I had to leave the login form visible, but I shrunk it down so only the title bar shows...Thanks for the help!
i'd make your login form not the main form...that's better.
X-Ray