Directives 

WITH..END WITH

Object Reference Construct

Format

WITH object ..END WITH

Where:

END WITH

Directive to end WITH construct

object

Object handle

Description

The WITH directive is used in Object Oriented Programming (OOP) to simplify the coding of multiple statements that refer to the same object. A logical "." variable is used in place of the object name prior to the Apostrophe Operator in all property/method references.

Example:

with Button_1.ctl
.'col=1,.'line=49,.'text$="Push Me"
end with

When a WITH directive is encountered, the current value of the logical "." variable is preserved on a stack, which is restored upon execution of an END WITH. Each WITH should be terminated by an END WITH. The "." variable is only allowed to be referenced as an object handle; therefore, any other "." references (without the Apostrophe Operator) are invalid.

Example:

. = 3

(Invalid)

print .

(Invalid)

.'value$="ABC"

(Valid)

The value of the "." variable is global; i.e. if it is set in mainline code, it will be maintained over a CALL or PERFORM to a subprogram or object method; however, if it changes, the change will not be passed back to the mainline. Subroutines (GOSUB) can change the value and alter the WITH stack.

The WITH stack is maintained separately from the GOSUB/FOR/WHILE stack. Each program level (CALL/PERFORM) has its own WITH stack, which is freed upon exit of the program level. The maximum number of WITH values that can be stacked is 20 per program level. Attempting to issue an END WITH without a corresponding WITH will generate an Error #27: Unexpected WEND, RETURN, or NEXT. Transferring into the middle of a WITH structure is allowed; however, it is the developer's responsibility to assure that the WITH stack is properly maintained.

The current value of "." is available in TCB(93).

(The WITH..END WITH directive was added in PxPlus v7.00.)

See Also

Object Oriented Programming