xHarbour Reference Documentation > Statement Reference xHarbour Developers Network  

WITH OBJECT

Identifies an object to receive multiple messages.

Syntax

WITH OBJECT <object>
 :<message1>
 [<statements>]
 [:<messageN>]
END

Arguments

WITH OBJECT <object>
<object> is the symbolic name of a variable that holds a reference to an object. The object is to receive messages in the WITH OBJECT control structure.
:<message>
All expressions that begin with the send operator in the OBJECT WITH block are sent as messages to <object>.

Description

The WITH OBJECT control structure delimits a block of statements where the object variable <object> receives multiple messages in abbreviated form. The name of the object variable can be omitted from a message sending expression, so that only the send operator (:) followed by the message to send must be typed.

WITH OBJECT basically relieves a programmer from typing. The name of the object variable is typed only once at the beginning of the WITH OBJECT block, and all subsequent messages sent to the object start with the send operator, omitting the object's variable name.

Info

See also:CLASS, METHOD (implementation), HB_QWith(), HB_SetWith()
Category: Control structures , Statements , xHarbour extensions

Example

// The example builds a simple database browser using a TBrowse object.
// The columns added to the object and the cursor navigation logic is
// programmed using the WITH OBJECT control structure.

   #include "inkey.ch"

   PROCEDURE Main
      LOCAL oTBrowse, aFields, cField, nKey

      USE Customer

      aFields := Array( FCount() )

      AEval( aFields, {|x,i| aFields[i] := FieldName(i) } )

      oTBrowse := TBrowseDB()

      WITH OBJECT oTBrowse
         FOR EACH cField IN aFields
            :addColumn( TBColumnNew( cField, FieldBlock( cField ) ) )
         NEXT
      END

      nKey := 0
      DO WHILE nKey <> K_ESC

         WITH OBJECT oTBrowse
            DO WHILE .NOT. :stabilize()
            ENDDO

            nKey := Inkey(0)

            SWITCH nKey
            CASE K_UP
              :up()       ; EXIT
            CASE K_DOWN
              :down()     ; EXIT
            CASE K_LEFT
              :left()     ; EXIT
            CASE K_RIGHT
              :right()    ; EXIT
            CASE K_PGUP
              :pageUp()   ; EXIT
            CASE K_PGDN
              :pageDown() ; EXIT
            CASE K_HOME
              :home()     ; EXIT
            CASE K_END
              :end()      ; EXIT
            END
         END
      ENDDO

      CLOSE Customer
   RETURN

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