How to change the main project form

<< Click to Display Table of Contents >>

Navigation:  Forum >

How to change the main project form

Forum link

 

 

 


 

10-13-2020, 05:03 AM:

 

When creating the project, the main form was created as a registration form. During the development of the project, it became necessary to show the welcome form before the registration form. The welcome form has been created in the project, but how can I assign it as the main one in the project?

 

 

 


 

10-13-2020, 11:20 AM:

 

Hi, in the end of the registration form, remove:

 

Code:

 

initialization

 

  TIWForm_Registration.SetAsMainForm;

 

and in the end of welcome form, put:

 

Code:

 

initialization

 

  TIWForm_Welcome.SetAsMainForm;

 

 

 

 

 


 

10-13-2020, 03:39 PM:

 

This call can also be made in the DPR file before the application is started. Example:

 

{$R *.res}

 

begin

 

TMainPage.SetAsMainForm;

 

TIWStart.Execute(True);

 

end.

 

 

 


 

10-14-2020, 06:33 AM:

 

I'm not using this, but I've seen others mention setting during session start:

 

Code:

 

procedure TApplServer.IWServerControllerBaseNewSession(ASession: TIWApplication);

 

begin

 

 &nbsp;&nbsp;ASession.Data:=TApplSession.Create(nil, ASession);

 

// &nbsp;&nbsp;if ASession.Browser.IsMobile then TMyMobileForm.SetAsMainForm else TMyStandardForm.SetAsMainForm;

 

end;

 

 

 

EDIT NOTE: See Kudzu comments below, setting main form in NewSession is NOT recommended and may cause problems.

 

Dan

 

 

 


 

10-14-2020, 08:44 AM:

 

Thank you, it works!

 

 

 


 

10-14-2020, 04:47 PM:

 

Doing so on new session is not a good idea. SetAsMainForm is a global setting and OnNewSession is threaded. This approach will create issues and could even cause crashes.

 

If you want to control which form is displayed dynamically use this event on the SC instead and create an instance of the form itself and return it in the var argument:

 

procedure TIWServerController.IWServerControllerBaseGetMainForm(var vMainForm: TIWBaseForm);

 

begin

 

 

 

end;

 

 

 


 

10-15-2020, 02:49 AM:

 

(10-14-2020, 04:47 PM)kudzu Wrote: [ -> ]Doing so on new session is not a good idea. SetAsMainForm is a global setting and OnNewSession is threaded. This approach will create issues and could even cause crashes.

 

If you want to control which form is displayed dynamically use this event on the SC instead and create an instance of the form itself and return it in the var argument:

 

procedure TIWServerController.IWServerControllerBaseGetMainForm(var vMainForm: TIWBaseForm);

 

begin

 

 

 

end;

 

Noted, thanks.  I haven't used that approach, just saw it used elsewhere a while back.   I will also edit the post to note this.

 

Dan

 

 

 


 

11-23-2024, 12:04 PM:

 

(10-14-2020, 04:47 PM)kudzu Wrote: [ -> ]Doing so on new session is not a good idea. SetAsMainForm is a global setting and OnNewSession is threaded. This approach will create issues and could even cause crashes.

 

If you want to control which form is displayed dynamically use this event on the SC instead and create an instance of the form itself and return it in the var argument:

 

procedure TIWServerController.IWServerControllerBaseGetMainForm(var vMainForm: TIWBaseForm);

 

begin

 

 

 

end;

 

I'm trying to use IWServerControllerBaseGetMainForm(var vMainForm: TIWBaseForm)

 

Inside, I simply call:

 

WebApplication.ShowForm(TfrmDefault, TRUE, TRUE);

 

and it works. But I must be misusing it, i.e.: what about the “var vMainForm: TIWBaseForm” parameter? – should I be freeing any that is passed in, or setting back the value of the form I create here?