[<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
  Method                         Define a Method 
------------------------------------------------------------------------------


 SYNTAX:

    [<preScope>] METHOD  <cUdf>[(param)] [<postScope>] [CONSTRUCTOR]

    [<preScope>] MESSAGE <cUdf>[(param)] [<postScope>] [CONSTRUCTOR]

    [<preScope>] MESSAGE <cMsg> METHOD <cUdf>[(param)] 

    [<preScope>] METHOD  <cUdf1>[(param)][,<cUdf2>[(param)]] 

    [<preScope>] METHOD <cMsg1>[(param)] = <cUdf1>[(param)] ; 
               [,METHOD <cMsg2>[(param)] = <cUdf2>[(param)]] 
     


 PARAMETER:

  <Scope>      Specifies the visibility of the method. Any declararion
               here overrides the default visibiltiy settings : 

               PUBLIC  | EXPORT 
               This is the default scope for all methods. You can invoke it
               from anywhere outside or inside the class :

                +------------------------------------------------+
                |  /* Invoke a public method */                  |
                |  ::MyPublic()           ; valid inside and     |
                |  oMyClass:MyPublic()    ; outside the class    |
                +------------------------------------------------+


               LOCAL   | HIDDEN  
               The method is not visible outside the class, which means that
               you can only invoke it via Self :

                +------------------------------------------------+
                |  /* Invoke a private method */                 |
                |  ::MyPrivate()          ; valid                |
                |  oMyClass:MyPrivate()   ; RUNTIME ERROR!       |
                +------------------------------------------------+


               You can put the scope declaration eiter in front of the 
               method (preScope) or behind it (postScope). Note that you
               can't use both ways in one command !

               Please press  Related Topics:  and select  EXPORT  for
               more informations about scopes


  <cUdf>       Is the actual name of the method function, optionally with
               a parameter declaration. A method of this name must be defined
               in the same module ( .PRG ) as the class definition, using the 
               METHOD <cUdf>( params ) command.


  <cMsg>       This argument defines the message that will invoke the method
               <cUdf>. By default, method and message names are the same,
               but there are some situations where this is not possible:
                
               1) If the <cUdf> method name conflicts with a name that is
                  already reserved by Clipper, like SET, LEFT or ARRAY. 
                  To use this keywords as a message, simply map them to a 
                  different method name :

                  +--------------------------------------+
                  |  /* Declare a LEFT message */        |
                  |  MESSAGE left METHOD myleft          |
                  +--------------------------------------+

                  o:left will now invoke the method function myLeft()
                  
               2) If you define more than one class in one module ( prg ),
                  to avoid duplicated function names like NEW()

               3) To avoid endless loops: If your method is called RECNO
                  and you invoke Clipper's Recno() function from it, you 
                  would end up calling your own method again. 

               4) to map two or more messages of your class to the same 
                  method:

                  +--------------------------------------+
                  |  /* 2 ways to call APPEND */         |
                  |  MESSAGE add    METHOD addrec        |
                  |  MESSAGE append METHOD addrec        |
                  |  METHOD  addrec                      |
                  +--------------------------------------+
                  
                  all three messages will now invoke ADDREC()



  CONSTRUCTOR  This keyword defines the method as a CONSTRUCTOR method.
               With Class(y), such a method will instantiate and then 
               initialize a new Object. In C++, the Constructor method of a
               class is automatically invoked by the compiler to initialize
               the Object directly after it has been created. With FiveWin,
               however, only the class function ( for example TWINDOW()) will 
               instanitate an Object. A Constructor method only returns a
               reference to Self ( even if you RETURN Nil ), so it is pretty
               useless, as you can return Self from your Init method anyway.  


 DESCRIPTION:

  This commands are used inside the class definition to add one ore more new
  methods to that class. The actual code of the method(s) must reside in the
  the same module as the class definition, unless the method is marked as 
  extern. 
  
  Methods defined in this way will be invoked by sending the message <cMsg>
  to an Object of their class, and they will receive a reference to that
  object as SELF.


   
 EXAMPLE:


    +--------------------------------------------------------------+
    |  /* Several valid method declarations */                     |
    |  METHOD open                                                 |
    |  METHOD close, use                                           |
    |  METHOD begin( cName, lState )                               |
    |  MESSAGE end()                                               |
    |                                                              |
    |  /* Override the default scope */                            |
    |  HIDDEN:                                                     |
    |    METHOD save PUBLIC                                        |
    |    EXPORT MESSAGE setfocus METHOD myFocus( oLast )           |
    |                                                              |
    |  /* Assine different Message/Method names */                 |
    |  MESSAGE delete METHOD mydelete                              |
    |  METHOD left = myleft, right = myright                       |
    |                                                              |
    |  /* Use a different Constructor method  */                   |
    |  MESSAGE init METHOD TableInit  CONSTRUCTOR                  |
    |                                                              |
    +--------------------------------------------------------------+




See Also: Export Extern SetGet Virtual Inline Block
This page created by ng2html v1.05, the Norton guide to HTML conversion utility. Written by Dave Pearson