ERROR HANDLER

ERROR HANDLER

Designate a method as an error handler for the class

Syntax

      ERROR HANDLER <MethodName>( [<params,...>] )

Arguments

<MethodName> Name of the method to define

<params, …> Optional parameter list

Description

ERROR HANDLER names the method that should handle errors for the class being defined.

Examples

      CREATE CLASS TWindow
         ERROR HANDLER  MyErrHandler()
      ENDCLASS

Compliance

Harbour

Platforms

All

Seealso

Object Oriented Programming, ON ERROR, CLASS, METHOD, DATA

ENDCLASS

ENDCLASS

End the declaration of a class.

Syntax

      ENDCLASS

Arguments

(This statement has no arguments)

Description

ENDCLASS marks the end of a class declaration. It is usually followed by the class methods that are not INLINE.

Examples

      CREATE CLASS TWindow
         VAR hWnd, nOldProc
      ENDCLASS

Compliance

Harbour

Platforms

All

Seealso

Object Oriented Programming, CLASS, METHOD, DATA

CLASS VAR

CLASS VAR

Define a CLASS VAR variable for a class (NOT for an Object!)

Syntax

      CLASS VAR <DataName1> [, <DataNameN>] [ AS <type> ] [ INIT <uValue> ]

Arguments

<DataName1> Name of the VAR

<type> Optional data type specification from the following:

Character, Numeric, Date, Logical, Codeblock, Nil

<uValue> Optional initial value at program startup

Description

CLASS VAR variables can also be thought of as the “properties” of an entire class. Each CLASS VAR exists only once, no matter how many objects are created. A common usage is for a counter that is incremented whenever an object is created and decremented when one is destroyed, thus monitoring the number of objects in existence for this class.

You can use the “AS <type>” clause to enforce that the CLASS VAR is maintained as a certain type. Otherwise it will take on the type of whatever value is first assigned to it.

Use the “INIT <uValue>” clause to initialize that VAR to <uValue> whenever the class is first used.

Examples

      CREATE CLASS TWindow
         VAR   hWnd,  nOldProc
         CLASS VAR lRegistered AS LOGICAL
      ENDCLASS

Compliance

Harbour

Platforms

All

Seealso

Object Oriented Programming, CLASS, METHOD, VAR

Class Template

Class Template
/* NOTE: - Please use these template for your new files, replace parts
 between curly braces {} with the appropriate text.
 - You can find a history at the end of the file. */
FILE HEADER TEMPLATE
====================
/*
 * Harbour Project source code:
 * {one-liner description about the purpose of this source file}
 *
 * Copyright 2000 {list of individual authors and e-mail addresses}
 * www - http://harbour-project.org
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this software; see the file COPYING.txt. If not, write to
 * the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
 * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/).
 *
 * As a special exception, the Harbour Project gives permission for
 * additional uses of the text contained in its release of Harbour.
 *
 * The exception is that, if you link the Harbour libraries with other
 * files to produce an executable, this does not by itself cause the
 * resulting executable to be covered by the GNU General Public License.
 * Your use of that executable is in no way restricted on account of
 * linking the Harbour library code into it.
 *
 * This exception does not however invalidate any other reasons why
 * the executable file might be covered by the GNU General Public License.
 *
 * This exception applies only to the code released by the Harbour
 * Project under the name Harbour. If you copy code from other
 * Harbour Project or Free Software Foundation releases into a copy of
 * Harbour, as the General Public License permits, the exception does
 * not apply to the code that you add in this way. To avoid misleading
 * anyone as to the status of such modified files, you must delete
 * this exception notice from them.
 *
 * If you write modifications of your own for Harbour, it is your choice
 * whether to permit this exception to apply to your modifications.
 * If you do not wish that, delete this exception notice.
 *
 */
FILE HEADER TEMPLATE (OPTIONAL ADDITION FOR PARTIAL COPYRIGHTS)
===============================================================
/*
 * The following parts are Copyright of the individual authors.
 * www - http://harbour-project.org
 *
 * Copyright 2000 {name} <{e-mail address}>
 * {function or subsystem name}
 *
 * See COPYING.txt for licensing terms.
 *
 */

CLASS HEADER TEMPLATE
========================
/* $CLASSDOC$
 $NAME$
$CATEGORY$
$ONELINER$
$CONSTRUCTOR$
$ARGUMENTS$
$RETURNS$
$DESCRIPTION$
$DATALINK$
$DATANOLINK$
$METHODSLINK$
$METHODSNOLINK$
$EXAMPLES$
$STATUS$
$COMPLIANCE$
$PLATFORMS$
$FILES$
$SEEALSO$
$END$
 */

/* $CLASSDOC$
 $METHOD$
$CATEGORY$
$ONELINER$
$SYNTAX$
$ARGUMENTS$
$RETURNS$
$DESCRIPTION$
$END$
 */
/* $CLASSDOC$
 $DATA$
$CATEGORY$
$ONELINER$
$DESCRIPTION$
$END$
 */
Source : https://github.com/harbour/core/blob/master/doc/class_tp.txt

: Send

 


 :
 Send--binary                                    (Object)
------------------------------------------------------------------------------
 Syntax

     <object>:<message>[(<argument list>)]

 Type

     Object

 Operands

     <object> is the name of the object that is to receive the message.

     <message> is the name of a method or instance variable.

     <argument list> is a list of parameters that are passed to the
     specified message.  The parentheses surrounding the argument list are
     optional if no parameters are supplied in the message send.  By
     convention, however, parentheses distinguish a message send with no
     parameters from an access to an exported instance variable.

 Description

     Each class defines a set of operations that can be performed on objects
     of that class.  Perform these operations by sending a message to the
     object using the send operator (:).

     When a message is sent to an object, the system examines the message.
     If the object is of a class that defines an operation for that message,
     the system automatically invokes a method to perform the operation on
     the specified object.  If the class does not define a method for the
     specified message, a runtime error occurs.

     Executing a message send produces a return value, much like a function
     call.  The return value varies depending on the operation performed.

 Examples

     .  In this example, myBrowse is the name of a variable that
        contains a TBrowse object reference.  pageUp() is a method that
        specifies the operation to be performed.  The available operations
        and corresponding methods vary depending on the class of the object.
        The Error, Get, TBColumn, and TBrowse classes are documented in this
        chapter.

        myBrowse:pageUp()

     .  This example forces the checkbox state to true (.T.):

        myCheck : Select (.T.)

TFileRead()

TFileRead()

Read a file one line at a time

Syntax

      oFile := TFileRead():New( <cFileName> [, <nReadSize> ] )

Arguments

<cFileName> is the required name of the file to be read.

<nReadSize> is the optional size to use when reading from the file. The default value is 4096 and the allowed range is 1 through 65535. Any value outside of this range causes the default value to be used.

Returns

An instance of the File Reader class

Description

TFileRead() is used to access a file one line at a time. You must specify the name of the file when an instance of the class is created.

The class data should be considered private to the class.

The class methods are as follows:

New() Creates a new instance of the TFileRead class.

Open([<nFlags>]) Opens the file for reading. The optional nFlags parameter can use any of the FOPEN() flags from fileio.ch. The default is FO_READ + FO_SHARED. Calling this method when the file is already open causes the next ReadLine() to start over from the beginning of the file.

Close() Closes the file.

ReadLine() Returns one line from the file, stripping the newline characters. The following sequences are treated as one newline:

          1) CR CR LF; 
          2) CR LF; 
          3) LF; and 
          4) CR. 

          Note: LF CR is 2 newlines.

Name() Returns the name of the file.

IsOpen() Returns .T. if the file is open.

MoreToRead() Returns .T. if there are more lines to be read (think of it as an inverse EOF function).

Error() Returns .T. if an error has occurred

ErrorNo() Returns the current error code.

ErrorMsg([<cPre>]) Returns a formatted error message.

Examples

      PROCEDURE Main( cFile )
         LOCAL oFile := TFileRead():New( cFile )

         oFile:Open()
         IF oFile:Error()
            OutStd( oFile:ErrorMsg( "FileRead: " ) )
            OutStd( hb_eol() )
         ELSE
            DO WHILE oFile:MoreToRead()
               OutStd( oFile:ReadLine() )
               OutStd( hb_eol() )
            ENDDO
            oFile:Close()
         ENDIF
         RETURN

Tests

      See Examples

Compliance

This is a new Harbour Tools class

Files

Library is libmisc

Seealso

TClass()

Download a test program (File Copy)  (Test_TFR.prg).