Page 1 of 1

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

Posted: Wed Jul 04, 2018 12:59 pm
by dannyoorburg
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

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

Posted: Wed Jul 04, 2018 3:44 pm
by soa
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.

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

Posted: Thu Jul 19, 2018 1:01 am
by atostaine
I agree. I like this idea. Art