Redirect in form constructor

<< Click to Display Table of Contents >>

Navigation:  Forum >

Redirect in form constructor

Forum link

 


 

03-16-2022, 08:42 AM:

 

Hi,

 

Since I migrated to IW15, something I was doing previously does not work anymore. In the WebApp main form (which is a login page), I was reading parameters from the URL in order to bypass the login view if the correct "auth_token" is provided trough the URL parameters. This detection was done directly in the login form constructor :

 

Code:

 

constructor TLoginView.Create(AOwner: TComponent);

 

var

 

...

 

begin

 

  if WebApplication.RunParams.Values['username'] <> '' then

 

  begin

 

    txtUserName.Text := WebApplication.RunParams.Values['username'];

 

    LUserCredentials := True;

 

  end;

 

  if WebApplication.RunParams.Values['auth_token'] <> '' then

 

  begin

 

      txtPassword.Text := AuthTokenToPassword(WebApplication.RunParams.Values['auth_token']);

 

      LPwdCredentials := True;

 

  end

 

  ...

 

  if tryLogin then

 

     with TMainView.Create(WebApplication) do Show;

 

 

 

This code does not work anymore in IW15. 

 

I tried using a timer and executing this code inside it, and it works. I suppose it is because the timer code is executed after the form is rendered and not in the form constructor. But is it the best way to handle a such redirection, or is there another recommended method ?

 

Best regards,

 

Adrien

 


 

03-17-2022, 09:43 AM:

 

The recommended way is to use ServerController's OnGetMainForm event. From that event you can inspect the request and decide which form to create.

 

Please note that you should create the instance of the form and pass it using the vMainForm parameter

 

procedure TIWServerController.IWServerControllerBaseGetMainForm(var vMainForm: TIWBaseForm);

 

begin

 

if SomeCondition then

 

vMainForm := TMyMainForm.Create(WebApplication);

 

end;

 


 

03-17-2022, 10:49 PM:

 

Thank you very much for your answer. Will try ASAP !

 

Cheers from France,

 

Adrien