Valutazione attuale: 0 / 5

Stella inattivaStella inattivaStella inattivaStella inattivaStella inattiva
 

METHOD

Declare a METHOD for a class in the class header
Syntax
METHOD <MethodName>( [<params,...>] ) [CONSTRUCTOR]
METHOD <MethodName>( [<params,...>] ) INLINE <Code,...>
METHOD <MethodName>( [<params,...>] ) BLOCK <CodeBlock>
METHOD <MethodName>( [<params,...>] ) EXTERN <NAME>( [<args,...>] )
METHOD <MethodName>( [<params,...>] ) SETGET
METHOD <MethodName>( [<params,...>] ) VIRTUAL
METHOD <MethodName>( [<param>] ) OPERATOR <op>
METHOD <MethodName>( [<params,...>] ) CLASS <ClassName>
Argument(s)
<MethodName> Name of the method to define
<params,...> Optional parameter list
Description
Methods are "class functions" which do the work of the class. All methods must be defined in the class header between the CLASS and ENDCLASS commands. If the body of a method is not fully defined here, the full body is written below the ENDCLASS command using this syntax:
METHOD <MethodName>( [<params,...>] ) CLASS <ClassName>
Methods can reference the current object with the keyword "Self:" or its shorthand version "::".
CLAUSES:
CONSTRUCTOR Defines a special method Class Constructor method,
used to create objects. This is usually the New() method. Constructors always return the new object.
INLINE Fast and easy to code, INLINE lets you define the
code for the method immediately within the definition of the Class. Any methods not declared INLINE or BLOCK must be fully defined after the ENDCLASS command. The <Code,...> following INLINE receives a parameter of Self. If you need to receive more parameters, use the BLOCK clause instead.
BLOCK Use this clause when you want to declare fast 'inline'
methods that need parameters. The first parameter to <CodeBlock> must be Self, as in:
METHOD <MethodName> BLOCK {| Self, <arg1>, <arg2>, ..., <argN> | ... }
EXTERN If an external function does what the method needs,
use this clause to make an optimized call to that function directly.
SETGET For calculated Data. The name of the method can be
manipulated like a Data element to Set or Get a value.
VIRTUAL Methods that do nothing. Useful for Base classes where
the child class will define the method's behavior, or when you are first creating and testing a Class.
OPERATOR Operator Overloading for classes.
See example tests/testop.prg for details.
CLASS <ClassName>
Use this syntax only for defining a full method after the ENDCLASS command.
Example(s)
CREATE CLASS TWindow
   VAR    hWnd, nOldProc
   METHOD New( ) CONSTRUCTOR
   METHOD Capture() INLINE  SetCapture( ::hWnd )
   METHOD End() BLOCK  {| Self, lEnd | iif( lEnd := ::lValid(), ;
      ::PostMsg( WM_CLOSE ), ), lEnd }
   METHOD EraseBkGnd( hDC )
   METHOD cTitle( cNewTitle ) SETGET
   METHOD Close() VIRTUAL
ENDCLASS
METHOD New( ) CLASS TWindow
   LOCAL nVar, cStr
   ... <code> ...
   ... <code> ...
   RETURN Self
Status
Ready
Compliance
This is Harbour specific
Platform(s)
This is available on all platforms
See also

HBClass(), Object Oriented Programming, VAR, CLASS