Jump to content

Hide Main Form


dionel1969
 Share

Recommended Posts

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.

Link to comment
Share on other sites

  • 11 months later...

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;

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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,

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...