Atozed Forums
How to change the main project form - Printable Version

+- Atozed Forums (https://www.atozed.com/forums)
+-- Forum: Atozed Software (https://www.atozed.com/forums/forum-1.html)
+--- Forum: IntraWeb (https://www.atozed.com/forums/forum-3.html)
+---- Forum: English (https://www.atozed.com/forums/forum-16.html)
+----- Forum: IntraWeb General Discussion (https://www.atozed.com/forums/forum-4.html)
+----- Thread: How to change the main project form (/thread-2051.html)



How to change the main project form - Сергей Александрович - 10-13-2020

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?


RE: How to change the main project form - Jose Nilton Pace - 10-13-2020

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;



RE: How to change the main project form - kudzu - 10-13-2020

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.


RE: How to change the main project form - DanBarclay - 10-14-2020

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


Code:
procedure TApplServer.IWServerControllerBaseNewSession(ASession: TIWApplication);
begin
   ASession.Data:=TApplSession.Create(nil, ASession);

//   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


RE: How to change the main project form - Сергей Александрович - 10-14-2020

Thank you, it works!


RE: How to change the main project form - kudzu - 10-14-2020

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;


RE: How to change the main project form - DanBarclay - 10-15-2020

(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


RE: How to change the main project form - iwuser - 11-23-2024

(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?