Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to change the main project form
#1
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?
Reply
#2
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;
Reply
#3
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.
Reply
#4
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
Reply
#5
Thank you, it works!
Reply
#6
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;
Reply
#7
(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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)