[<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
  VAR, DATA, INSTVAR             Defines an Instance Variable of a class
------------------------------------------------------------------------------


 SYNTAX:

     [ Scope ] VAR <xVar> [,<xVarN>] ;
              [ AS <cTyp> [,<cTypN>] ; 
              [ DEFAULT | INIT <uInit> ] [ INSTANTIATE ] ; 



 PARAMETER:

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

                PUBLIC   | EXPORT     ; Default  
                READONLY | PROTECTED  ; Readonly outside a Method
                LOCAL    | HIDDEN     ; invisible outside a Method

               please press  Related Topics:  and select  EXPORT  for
               more informations about the different scopes

       
  <xVar,xVarN> Is the Name ( Message ) of the variable, of a list of Names.
               It can be any string that uniquely identifies our DATA. You
               should choose a meaningfull name to get an understanding of
               the programm by reading the source code.
               Also, using hungarian notation ( specifying the vartype as
               the first char of the name , like cVar for a charVar, or
               nVar for a numerical ) is a good choice.

               Please note, that only the first nine chars of the string are
               significant! This is because Clipper in fact defines two 
               Messages for each data: 

                - one Message with the give <xVar> name to access the DATA,
                - and one Message <_xVar> with a leading underscore to
                  assign a value to the DATA.

               This is a very handy feature to create SETGET Methods, but
               it also decreases the significant length of a varname by one.


   <cTyp,cTypN> Specifies the Type of var, or a list of types, that can be
               assigned to our Instance Variable. This gives us something 
               like 'strong typing', if you try to assign an invalid valtype
               to an instance var, you will produce a 'Type-Protected Var
               Error' [4]. Don't underestimate this feature, it can save
               you a lot of debugging time.  These are your canditates :
               
                ALL         ; No scoping; this is the default 
                NIL         ; var can be NIL also, usefull for destructors
                UNDEFINED   ; same as NIL 
                CHARACTER   ; var can only hold a string value 
                NUMERIC     ; Integer, Long Integer or Floating Point var
                LOGICAL     ; must be a boolean .T. or .F.
                BLOCK       ; Codeblock is expected
                DATE        ; var holds a DATE value
                ARRAY       ; only Arrays allowed
                OBJECT      ; iVar is an object container 
                
               You may combine keywords to a list of valid types, like
               AS OBJECT, NIL or AS CHARACTER, NUMERIC. This is
               sometimes necessary if you want to delete the contents of an
               Instance Var by assigning NIL to it.
               

  <uInit>       Is a default value that will be assigned to the Instance var
               after the object is created. Normally you have to init each 
               iVar in the Constructor Method of its class. The 
               DEFAULT/INIT clause lets you handle this automatically in
               the Design stage.
               If you assign an Array to an iVar using the INIT Keyword,
               every object will be initialized with a reference to the same
               Array, so if you change this Array at runtime, the changes
               will reflect on every instance of the class, just like a
               change to a public Array.
               This behaviour is normally expected only for class vars, so
               you can change it using the INSTANTIATE Keyword.
               By specifying this, every new object will receive a copy of
               the INIT value.
                                
  

 DESCRIPTION:

  This command lets you define an Instance Variable and add it to a class.
   


 EXAMPLE:


    +--------------------------------------------------------------+
    |  /* Several DATA Definitions */                              |
    |   DATA    nRow                                               |
    |   VAR     nCol                                               |
    |   DATA    bAction, bFocus                                    |
    |   DATA    cName AS CHAR INIT "DEMO"                          |
    |   DATA    aProp INIT {} INSTANTIATE                          |
    |   DATA    cName AS CHAR INIT "DEMO"                          |
    |   DATA    aProp INIT {} INSTANTIATE                          |
    |                                                              |
    +--------------------------------------------------------------+


  


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