how to check if the form is open ?

Discussions about design and architecture principles, including native JADE systems and JADE interoperating with other technologies
Jay
Posts: 25
Joined: Mon Jul 23, 2018 10:15 am

how to check if the form is open ?

Postby Jay » Mon Jul 23, 2018 12:09 pm

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.

User avatar
WilliamC
Posts: 2
Joined: Mon Jul 23, 2018 12:25 pm
Location: CHCH, New Zealand

Re: how to check if the form is open ?

Postby WilliamC » Mon Jul 23, 2018 12:31 pm

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

Jay
Posts: 25
Joined: Mon Jul 23, 2018 10:15 am

Re: how to check if the form is open ?

Postby Jay » Mon Jul 23, 2018 3:40 pm

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 !

User avatar
BeeJay
Posts: 312
Joined: Tue Jun 30, 2009 2:42 pm
Location: Christchurch, NZ

Re: how to check if the form is open ?

Postby BeeJay » Mon Jul 23, 2018 4:51 pm

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.


Return to “Design and Architecture”

Who is online

Users browsing this forum: No registered users and 6 guests