BBjAPI::getExistingNamespace

Description

In BBj 3.00 and higher, this method retrieves a BBjNamespace.

Syntax

Return Value

Method

BBjNamespace

getExistingNamespace(string name)

Parameters

Variable

Description

name

Specifies the name of the Namespace to be referenced.

Return Value

Returns a BBjNamespace that references the specified Namespace.

Remarks

If the requested Namespace does not already exist, then an !ERROR=63 - Uninitialized Variable will be generated.

Executing the getName() method on the returned BBjNamespace returns the Namespace name that can be subsequently used with the getNamespace and getExistingNamespace methods.

Example

sysgui = unt
open (sysgui)"X0"
api! = BBjAPI()
sysgui! = api!.getSysGui()

rem 'retrieve a namespace, get value of count
switch argc
    case 1
        rem 'run from command line with no namespace name
        prefix$ = "basis.eng.test.namespace"
        sharedNSName$ = "test"
        sharedNS! = api!.getNamespace(prefix$, sharedNSName$, 1)
        break
    case 2
        rem 'run from command line with a namespace name
        prefix$ = argv(1)
        sharedNSName$ = "test"
        sharedNS! = api!.getNamespace(prefix$, sharedNSName$, 1)
        break
    case 3
        rem 'run from within MDI
        prefix$ = "basis.eng.test"
        sharedNSName$ = argv(1)
        sharedNS! = api!.getExistingNamespace(sharedNSName$)
        break
swend
count = sharedNS!.getValue("count", err = setCount)
privateNS! = api!.getNewNamespace(prefix$)
privateNS!.setValue("count",0)
name$ = "client-" + privateNS!.getName()

rem 'retrieve position
rem 'x = sharedNS!.getValue("x", err = setXY)
y = sharedNS!.getValue("y", err = setXY)

rem 'increment position
rem 'sharedNS!.setValue("x", x+50)
sharedNS!.setValue("y", y+50)

rem 'create window
rem 'window! = sysgui!.addWindow(x,y,300,200,name$)
plus! = window!.addButton(1,5,10,90,30,"Increment")
minus! = window!.addButton(2,105,10,90,30,"Decrement")
window!.addStaticText(101,5,50,290,30,"sharedCount:   ")
window!.addStaticText(102,5,70,290,30,"privateCount: ")
sharedCount! = window!.addStaticText(103,200,50,290,15,str(count))
privateCount! = window!.addStaticText(104,200,70,290,15,str(0))
break! = window!.addButton(3,5,110,90,30,"Break")
break!.setCallback(break!.ON_BUTTON_PUSH,"onBreak")

rem 'set callback for controls
rem 'plus!.setCallback(plus!.ON_BUTTON_PUSH, "onPlus")
minus!.setCallback(plus!.ON_BUTTON_PUSH, "onMinus")
window!.setCallback(window!.ON_ACTIVATE, "onActivate")

rem 'set callback that is to be called when count changes
sharedNS!.setCallbackForVariable("count", "showCount")
privateNS!.setCallbackForVariable("count", "showCount")

rem 'call onActivate to set tell others we have activated
gosub onActivate
callback(ON_CLOSE,done,sysgui!.getContext())
process_events

onPlus:
    sharedNS!.setValue("count", 1 + sharedNS!.getValue("count"))
    privateNS!.setValue("count", 1 + privateNS!.getValue("count"))
return

onMinus:
    sharedNS!.setValue("count", -1 + sharedNS!.getValue("count"))
    privateNS!.setValue("count", -1 + privateNS!.getValue("count"))
    count = count - 1
return

onActivate:
    print "onActivate called"
    sharedNS!.setValue("activeClientNS", privateNS!.getName())
    sharedNS!.setValue("activeClientName",name$)
return

showCount:
    sharedcount!.setText(str(sharedNS!.getValue("count")))
    privatecount!.setText(str(privateNS!.getValue("count")))
return

onBreak:
    escape
return

done:
release

setXY:
    x = 100
    y = 100
    sharedNS!.setValue("x", x)
    sharedNS!.setValue("y", y)
retry

setCount:
    count = 0
    sharedNS!.setValue("count", count)
retry

See Also

BBjAPI

Object Variables

See the BBj Object Diagram for an illustration of the relationship between BBj Objects.