Jump to content

Form is always shown after being created


arilotta

Recommended Posts

Hi,

using VCL I usually create a form and initialize it calling a "startup" method; thsi method is repsonsible to set up the form, open 

the queries and finally display the form. During that phase, if an exception is raised implicitely or explicitely, the relative message

is shown to the user and the form is not shown.

Something like this:

 

with TMyForm.Create(self)

try

  Initialize(.., ...);

finally

  Free;

end;

 

procedure TMyForm.Initailize(..., ...);

begin

  // form initialization...

  raise Exception.Create('some error');

  ShowModal;

end;

 

In the above example, the form is created, the Initailize method is executed until the exception, finally the form is freeid.

 

I'm unable to achieve the same behaviour with UniGUI, as it seems that the forms are automatically shown after being created.

I've tried something like this, but it gives a Javascript error:

 

procedure TMyForm.Initailize(..., ...);

begin

  try

    // form initialization...

    raise Exception.Create('some error');

    ShowModal;

  except

    self.Close;

  end;

end;

 

Is there a solution ? Or, which is the best way to initialize a form ?

 

Andrea

Link to comment
Share on other sites

Thank you, after analyzing the link you've posted, I find a solution, I'm posting it here just in case anyone has the same problem:

 

----------------------------------------------------------------

 

In main form:

 

MyForm.Initialize(..., ...)

 

In MyForm:

 

procedure TMyForm.UniFormCreate(Sender: TObject);
begin
  // form initialized as not visible
  self.ClientEvents.ExtEvents.Add
      ('window.afterlayout=function afterlayout(sender, layout, eOpts)'+
      ' {  Ext.get(sender.id).el.setVisible(false); }');
end;
 

procedure TMyForm.Initialize(..., ...);

begin

  try

    // form initialization...

    raise Exception.Create('some error');

    ShowModal;

    UniSession.AddJS('setTimeout(function(){'+self.WebForm.JSName+'.el.setVisible(true); }, 0)' );

  except

    TMRClose.Enabled:=true;

    self.Close;

  end;

end;

 

procedure TMyForm.TMRCloseTimer(Sender: TObject);

begin
 // TMRClose is a TUniTimer with Interval=1, RunOnce=true
  self.Close;
end;
Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...