dionel1969 Posted October 27, 2011 Posted October 27, 2011 Hello Everybody: I have the following question: How to hide MainForm at init to show only LoginForm??? i. e. at what point in the creation of MainForm I can do that??? I try it in the OnCreate and is not possible, also putting Visible field to False in Design Time. The situation is the following: I want to show first LoginForm without MainForm in the back. When LoginForm closes, it will callback a procedure of MainForm, this procedure will show again MainForm is Ok is clicked and login process is successfully done, or just exit from App if Cancel button was clicked or process login come to X times (3 normally) if login process was not successfully. I made a test and I can hide MainForm, but not in the OnCreate. Then I make this and it works but, I have my doubts. It seem to be a patch more than a good code. UniForm1 <=> LoginForm unit Main; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, uniGUITypes, uniGUIAbstractClasses, uniGUIClasses, uniGUIForm, uniGUIBaseClasses, uniButton; type TMainForm = class(TUniForm) UniButton1: TUniButton; UniButton2: TUniButton; procedure UniButton1Click(Sender: TObject); procedure UniButton2Click(Sender: TObject); procedure UniFormShow(Sender: TObject); procedure UniFormCreate(Sender: TObject); private { Private declarations } fTime : Integer; public { Public declarations } end; function MainForm: TMainForm; implementation {$R *.dfm} uses uniGUIVars, MainModule, Unit1, Unit2; function MainForm: TMainForm; begin Result := TMainForm(UniMainModule.GetFormInstance(TMainForm)); end; procedure TMainForm.UniButton1Click(Sender: TObject); begin UniForm1.Show; end; procedure TMainForm.UniButton2Click(Sender: TObject); begin Hide; UniForm1.Show; end; procedure TMainForm.UniFormCreate(Sender: TObject); begin fTime := 0; end; procedure TMainForm.UniFormShow(Sender: TObject); begin fTime := fTime + 1; if (fTime = 1) then begin Hide; UniForm1.Show; end; end; initialization RegisterMainFormClass(TMainForm); end. Quote
zilav Posted October 27, 2011 Posted October 27, 2011 How about uni runonce timer with 100msec delay? Start it in oncreate event, on timer event show login form. Try to hide main form in oncreate, onshow or ontimer events. Not sure if it would work however. Quote
Administrators Farshad Mohajeri Posted November 4, 2011 Administrators Posted November 4, 2011 procedure TMainForm.UniFormShow(Sender: TObject); begin if WebMode then if not AFlag then begin Hide; AFlag:=True; LoginForm.Show; end; end; procedure TLoginForm.UniFormClose(Sender: TObject; var Action: TCloseAction); begin MainForm.Show; end; Quote
rencarnacion Posted October 18, 2012 Posted October 18, 2012 I try this code but I have problem with var flag what unit I must use in order to Use Flag in my form Thanks procedure TMainForm.UniFormShow(Sender: TObject); begin if WebMode then if not AFlag then begin Hide; AFlag:=True; LoginForm.Show; end; end; procedure TLoginForm.UniFormClose(Sender: TObject; var Action: TCloseAction); begin MainForm.Show; end; Quote
glendean Posted October 18, 2012 Posted October 18, 2012 did you try.... unit Main; ........... implementation {$R *.dfm} uses UniGUIVars, MainModule, Unit1; var aflag: boolean; Quote
glendean Posted October 18, 2012 Posted October 18, 2012 Be simpler to.... procedure TMainForm.UniFormShow(Sender: TObject); if WebMode then LogonForm.Show; end; And set LogonForm.WindowSate to wsMaximized so Mainform isn't view-able. If they fail logon ...unisession.TerminateAfterSecs(0) and then show another form saying .... "Session Has Ended" with option to restart If they logon ... LogonForm.close; Glen Quote
estrify Posted October 18, 2012 Posted October 18, 2012 Hi, In our application, the login is a mandatory action so we do a simple thing: develop a login form, adding the following to be the first form displayed: initialization RegisterMainFormClass(TfrmLogin); and deleting similar lines in the MainForm If the login succeeds, simply initialize what you need and do: frmLogin.Hide; frmMain.Show; All session flags and shared information, we put them in MainModule.pas as public members of TUniMainModule, so they are available for all session forms through UniMainModule function (be sure that MainModule is present under "uses" clause of your forms). It is very simple, but it works for us... Regards, Quote
dionel1969 Posted October 18, 2012 Author Posted October 18, 2012 Hi, In our application, the login is a mandatory action so we do a simple thing: develop a login form, adding the following to be the first form displayed: initialization RegisterMainFormClass(TfrmLogin); and deleting similar lines in the MainForm If the login succeeds, simply initialize what you need and do: frmLogin.Hide; frmMain.Show; All session flags and shared information, we put them in MainModule.pas as public members of TUniMainModule, so they are available for all session forms through UniMainModule function (be sure that MainModule is present under "uses" clause of your forms). It is very simple, but it works for us... Regards, Thank you for your comments. This issue I solved a time ago, but anyway thank you again for your help. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.