arilotta Posted June 7, 2017 Share Posted June 7, 2017 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 More sharing options...
Sherzod Posted June 7, 2017 Share Posted June 7, 2017 Hi, http://forums.unigui.com/index.php?/topic/8268-create-form-automatically-show/ Link to comment Share on other sites More sharing options...
arilotta Posted June 8, 2017 Author Share Posted June 8, 2017 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 More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now