Accessing views and the main page from anywhere in an app using Scope(*APPLICATION)

This forum allows developers to post programming tips and coding techniques that may be useful to other Visual LANSA developers. The information contained in this forum has not been validated by LANSA and, as such, LANSA cannot guarantee the accuracy of the information.
Post Reply
dannyoorburg
Posts: 146
Joined: Mon Jan 04, 2016 9:50 am
Location: Australia

Accessing views and the main page from anywhere in an app using Scope(*APPLICATION)

Post by dannyoorburg » Wed Jul 04, 2018 12:59 pm

Hi all,

I just found myself writing some code and thought it might be a useful concept to share with all LANSA 14.2 developers out there.

By setting up some useful global references in the CreateInstance event of my main page I now have access to the main page and its views from anywhere in my application.

Code: Select all

* Global references to the main application and its views
Define_Com Class(#A05Main) Name(#AppWebPage) Scope(*APPLICATION) Reference(*DYNAMIC)
Define_Com Class(#A05Contacts) Name(#AppContactsView) Scope(*APPLICATION) Reference(*DYNAMIC)

Evtroutine Handling(#COM_OWNER.CreateInstance)

* Initialize the global references
#AppWebPage <= #COM_OWNER
#AppContactsView <= #Contacts

Endroutine
So now, deep down in a reusable part, I can for instance easily navigate to a particular view with only a couple of lines of code...

Code: Select all

* A global reference to the one and only Contacts View
Define_Com Class(#A05Contacts) Name(#AppContactsView) Scope(*APPLICATION) Reference(*DYNAMIC)

Evtroutine Handling(#ShowContactsButton.Click)

#AppContactsView.Show

Endroutine
Or I can listen to an event coming from the main page inside any object in my application.

Code: Select all

* A global reference to the one and only Web Page
Define_Com Class(#A05Main) Name(#AppWebPage) Scope(*APPLICATION) Reference(*DYNAMIC)

Evtroutine Handling(#AppWebPage.MyEvent)

* ....

Endroutine
Let me know your thoughts... Is this goodness or does it break re-usability? Should reusable parts be agnostic of the application or is that just not worth the extra code?

Cheers,
Danny

soa
Posts: 277
Joined: Mon Dec 07, 2015 3:15 pm

Re: Accessing views and the main page from anywhere in an app using Scope(*APPLICATION)

Post by soa » Wed Jul 04, 2018 3:44 pm

This is a good tip Danny. Although re-usability is a good thing I find that RPs such as Views are very specific to a web application and this technique is clear and simple in use.

atostaine
Posts: 388
Joined: Wed Jan 20, 2016 7:38 am

Re: Accessing views and the main page from anywhere in an app using Scope(*APPLICATION)

Post by atostaine » Thu Jul 19, 2018 1:01 am

I agree. I like this idea. Art
Art Tostaine

Post Reply