Archive for the ‘Namespaces’ Category

Namespace

Posted: 2017-01-20 in Namespaces

Q:
my commandbutton is created using code in custom section
May I know what property I should set using code as I do not have an attributes panel for commanbutton created in code?
A:
In the top of your custom section, public the variable you are going to use for the button – under where it says namespace.
For example.

Code:
/
// Lianja custom section for page "page1" section "section2"
//
namespace gap
public tekbutton1
define class page1_section2 as section
.......
.......

Then anywhere in the code, you can just use
tekbutton1.hide
and of course to show it, you use tekbutton1.show.

tekbutton1.hide is the same thing as tekbutton1.visible = .f.
tekbutton1.show is the same thing as tekbutton1.visible = .t.



 

Namespace

Posted: 2017-01-20 in Namespaces

Namespaces allow you to declare public variables, which are only public within that namespace. So, I could have 2 separate public variables called m_var, providing at least one of them was in a namespace. A procedure or function with the same namespace declared would be able to access the m_var from that namespace or it could be accessed as namespace.m_var from anywhere. It’s useful if there is a risk of having conflicting public variable names – for example, if you are adding Page or Section templates or Pages from the Page Library to your App.


by specifying the namespace in a delegate or procedure, variables do not need to be prefixed by the namespace.

Code:
proc myDelegate()
    namespace PeopleKiosk 
    Public myvar
    // peoplekiosk.myvar and myvar reference the same variable
endproc

Tip #1: you can use the namespace() function to save the current namespace and set it back later in your code.
Tip #2: To disable the namespace just specify

Code:
namespace none
// or
namespace

Tip #3: how to inspect a namespace? Try this in the console.

Code:
namespace barry
public myvar = "hello world"
? barry

Surprise surprise, namespaces are just objects that encapsulate public variables and other things (more on that later).


Q:
I have a desktop app and I wish to make variable initialised in one page visible to all other pages
In my case, my initial page is a page with custom section
I have public some variables and initialised the values of these public variables but I am not able to see the variables value in other pages
May I know how I can expose the variables created in my custom section of my initial page to all other pages
A:
You probably have a namespace statement in your custom section code. That being the case you need to prefix the reference of your public variables by the name of the namespace e.g.

namespace myns
Public ui_message

in another page you must reference it like this
myns.ui_message