xHarbour Reference Documentation > Function Reference xHarbour Developers Network  

HB_SetWith()

Changes the with object during WITH OBJECT execution.

Syntax

HB_SetWith( [<oNewObject>] ) --> oOldObject

Arguments

<oNewObject>
If specified, <oNewObject> becomes the new with object, while oOldObject is pushed on the WITH OBJECT execution stack. If <oNewObject> is omitted, the last object from the WITH OBJECT execution stack becomes the current with object.

Return

The function returns the previous with object active in the WITH OBJECT statement.

Description

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.

Info

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

Example

// 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

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe