xHarbour Reference Documentation > Statement Reference |
Identifies an object to receive multiple messages.
WITH OBJECT <object> :<message1> [<statements>] [:<messageN>] END
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.
See also: | CLASS, METHOD (implementation), HB_QWith(), HB_SetWith() |
Category: | Control structures , Statements , xHarbour extensions |
// 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
http://www.xHarbour.com