xHarbour Reference Documentation > Function Reference |
Changes the with object during WITH OBJECT execution.
HB_SetWith( [<oNewObject>] ) --> oOldObject
The function returns the previous with object active in the WITH OBJECT statement.
Function HB_SetWith() changes the current with object in the context of the WITH OBJECT statement. All abbreviated messages within the WITH OBJECT .. END block are addressed to the current with object.
Passing an object to HB_SetWith() opens a new WITH .. OBJECT context, and pushes the current with object to the WITH OBJECT execution stack. As a result, function HB_WithObjectCounter() returns a value increased by 1.
The new WITH OBJECT context is closed by calling HB_SetWith() without parameter, so that a previous with object is removed from the WITH OBJECT execution stack, and HB_WithObjectCounter() returns a value decreased by 1.
See also: | HB_QSelf(), HB_ResetWith(), HB_QWith(), HB_WithObjectCounter(), WITH OBJECT |
Category: | Object functions , xHarbour extensions |
Source: | include\hbexprb.c |
LIB: | xhb.lib |
DLL: | xhbdll.dll |
// The example outlines the effect of calling HB_SetWith() // with and without parameter. Passing an object to the // function opens a new WITH OBJECT context. Note that the // new "with" object must be obtained with function HB_QWith() // when the new context is opened with the HB_SetWith() function // instead of the WITH OBJECT statement. PROCEDURE Main() WITH OBJECT ErrorNew() ? :className() // result: ERROR ? HB_WithObjectCounter() // result: 1 // opens new WITH OBJECT context HB_SetWith( GetNew() ) ? HB_QWith():className() // result: GET ? HB_WithObjectCounter() // result: 2 // closes new WITH OBJECT context HB_SetWith() ? :className() // result: ERROR ? HB_WithObjectCounter() // result: 1 END RETURN
http://www.xHarbour.com