Page 1 of 1
how to check if the form is open ?
Posted: Mon Jul 23, 2018 12:09 pm
by Jay
how to check if the form is open ? and if the form is open then do not open it again. If the form is not open the open it.
mnuAboutMe_click(menuItem: MenuItem input) updating;
vars
form:Form1;
begin
if Form1.instances.first = null then
create form transient;
form.show();
else
return;
endif;
end;
that's an example of how I did it and it didn't work.
Re: how to check if the form is open ?
Posted: Mon Jul 23, 2018 12:31 pm
by WilliamC
Form.instances are persistent instances, yours is transient nor are persistent instances aloud of forms.
What you could do is have a reference property on Form1 that when you trigger click event it assigns the newly created form to the reference so when you click again, check if it is not null, you then know it already exists.
or you could have it as simple as Form1.form2Exists : Boolean. if its true, dont create form2.
Alternatively, if you don't want users to use Form1 while Form2 is active, Form2.showModal() exists.
the first method would allow you to access Form2 from Form1 if you chose to hide it again on Form1
Re: how to check if the form is open ?
Posted: Mon Jul 23, 2018 3:40 pm
by Jay
Thank you for your help. You made a point that I could not figure out.
I figure out there is a function called
lastProcessTransientInstance
lastProcessTransientInstance(): InstanceType;
The lastProcessTransientInstance method of the Class class returns a reference to the last transient instance of the class that was created by the current process.
See also "Caveat When Handling Shared Transient Class Instances", earlier in this section.
this solved problems. Thank you !
Re: how to check if the form is open ?
Posted: Mon Jul 23, 2018 4:51 pm
by BeeJay
I wouldn't recommend using the 'instance' style methods, such as
lastProcessTransientInstance, in regularly executed production code. You would be better to use an approach like William suggested, assuming you have a 'main form' that controls access to your other forms.
Alternately, you can use the
Application::formsCount() and
Application::forms(formNumber:Integer) methods to iterate through all the currently open forms in your application to see if the form in question is already opened. This would be preferable to using any of the 'instance' style methods to see if a form is currently open.
Refer
https://www.jadeworld.com/docs/jade-201 ... scount.htm and
https://www.jadeworld.com/docs/jade-201 ... /forms.htm for further details.
Cheers,
BeeJay.