BBjAPI::getGroupNamespace

Description

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

Syntax

Return Value

Method

BBjNamespace

getGroupNamespace()

Parameters

None.

Return Value

Returns a BBjNamespace.

Remarks

A group of BBjProcesses is created each time that BBj is invoked from the command line. Any process that is created by SCALLing BBj within a thin client environment belongs to the same group. A process within a group that calls getGroupNamespace() will receive a BBjNamespace that refers to the same Namespace. This method provides a mechanism by which BBjProcesses within a group can share data and may communicate to other processes within that group.

Example

REM To see how the group namespace works, launch
REM two copies of this program.  With just one copy, every
REM program running will be in the same group.
REM Move the top window around and try resizing it.  The
REM reason that the child window is able to mimic the parent
REM is because the parent is setting its size and position
REM in the namespace and the child is responding to these
REM values being set.  Group namespaces are especially
REM useful in an MDI, where the children need to communicate
REM settings and application behaviour to one another or
REM the parent MDI Window.
declare BBjNamespace groupNS!
declare BBjSysGui sysgui!
declare BBjTopLevelWindow win!
sysgui!=BBjAPI().openSysGui("X0")
groupNS!=BBjAPI().getGroupNamespace()
print groupNS!.getName()
REM *** Parent program ***
if (argc<2) then
    win!=sysgui!.addWindow(10,10,160,120,"Namespace Example")
    
    REM give the namespace variables an initial value
    gosub updateGroupNS
    REM whenever the parent is moved or resized, update
    REM the namespace with the values.
    win!.setCallback(win!.ON_WINDOW_MOVE,"updateGroupNS")
    win!.setCallback(win!.ON_RESIZE,"updateGroupNS")
    win!.setCallback(win!.ON_CLOSE,"the_end")
    
    REM Scalled BBj programs are in the same group as
    REM process that invoked them.
    status_code=scall(argv(0)+" "+pgm(-2)+" - 2 &")
    
    process_events
else  
REM *** Child Program ***
    parentX=10
    parentY=10
    parentWidth=160
    parentHeight=120
    win!=sysgui!.addWindow(
:       parentX,
:       parentY+parentHeight+50,
:       parentWidth,
:       parentHeight,
:       "Child of Namespace Example")
    win!.setResizable(BBjAPI().FALSE)
    REM Callbacks on the namespace allow the child process
    REM to respond when the parent sets namespace values.
    groupNS!.setCallbackForVariableChange("X","x_changed")
    groupNS!.setCallbackForVariableChange("Y","y_changed")
    groupNS!.setCallbackForVariableChange("WIDTH","width_changed")
    groupNS!.setCallbackForVariableChange("HEIGHT","height_changed")
    groupNS!.setCallbackForVariable("BYE","the_end")
    process_events
endif
REM The parent's X position has been updated, so set the
REM X position of the child in response.
x_changed:
    x=cast(BBjNumber,groupNS!.getValue("X"))
    win!.setLocation(x,win!.getY())
    return
REM The parent's Y position has been updated, so set the
REM Y position of the child in response.
y_changed:
    y=cast(BBjNumber,groupNS!.getValue("Y"))
    height=cast(BBjNumber,groupNS!.getValue("HEIGHT"))
    win!.setLocation(win!.getX(),y+height+50)
    return
REM The parent's width has been updated, so set the
REM width of the child in response.
width_changed:
    width=cast(BBjNumber,groupNS!.getValue("WIDTH"))
    win!.setSize(width,win!.getHeight())
    return
REM The parent's height has been updated, so set the
REM height and y position of the child in response.
height_changed:
    height=cast(BBjNumber,groupNS!.getValue("HEIGHT"))
    heightChange=height-win!.getHeight()
    win!.setSize(win!.getWidth(),height)
    win!.setLocation(win!.getX(),win!.getY()+heightChange)
    return
REM Set the values in the namespace whenever the parent
REM has been moved or resized.
updateGroupNS:
    groupNS!.setValue("X",win!.getX())
    groupNS!.setValue("Y",win!.getY())
    groupNS!.setValue("HEIGHT",win!.getHeight())
    groupNS!.setValue("WIDTH",win!.getWidth())
    return
REM If the parent is closed, tell the child it's time
REM to close too, via the namespace.
the_end:
    groupNS!.setValue("BYE","true")
    release

See Also

BBjAPI

Object Variables

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