Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Redirect in form constructor
#1
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
Reply
#2
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;
Reply
#3
Thank you very much for your answer. Will try ASAP !

Cheers from France,

Adrien
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)