Announcement

Collapse
No announcement yet.

Unchangeable GLOBALS

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Unchangeable GLOBALS

    Here is a little snippit where you can define GLOBAL variables which cannot be change.
    Can be used in place of BYCOPY or as a substitute for EQUATES.

    James

    Code:
    '=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    'SED_PBCC
    ' An example of using a class to create GLOBAL variables that can be passed BYREF
    ' where the original cannot be changed outside the procedure.
    '=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    #IF NOT %DEF(%Prop_MACROS)
        %Prop_MACROS = 1
        MACRO PropGet(PropName,PropType)=PROPERTY GET PropName() AS PropType:PROPERTY=PropName:END PROPERTY
        MACRO PropSet(PropName,PropType)=PROPERTY SET PropName(BYVAL param AS PropType):PropName=param:END PROPERTY
    #ENDIF
    'Return Nacros
    #IF NOT %DEF(%RET_M_MACRO)
        %RET_M_MACRO = 1
        MACRO Ret_M(RetVal) = METHOD=RetVal:EXIT METHOD
    #ENDIF
    #IF NOT %DEF(%RET_F_MACRO)
        MACRO Ret_F(RetVal) = FUNCTION=RetVal:EXIT FUNCTION
        %RET_F_MACRO = 1
    #ENDIF
    '******************************************************************************
    CLASS cConst
        INSTANCE Id1,Id2,Id3 AS LONG
        CLASS METHOD CREATE
            Id1 = 1
            Id2 = 2
            Id3 = 3
        END METHOD
        INTERFACE iConst : INHERIT IUNKNOWN
            PropGet(Id1,LONG)
            PropGet(Id2,LONG)
            PropGet(Id3,LONG)
        END INTERFACE
    
    END CLASS
    
    GLOBAL Const AS iConst
    
    
    FUNCTION PBMAIN() AS LONG
            Const = CLASS "cConst"
    'Now Const is available throughout your program
            PRINT "In PbMain Before TestIt Call";Const.Id1
            TestIt Const.Id1
            PRINT "In PbMain After TestIt Call ";Const.Id1        
            TestIt02
            TestIt
            WAITKEY$
    END FUNCTION
    
    
    FUNCTION TestIt(OPT L1 AS LONG) AS LONG
        IF ISMISSING(L1) THEN
            ? "L1 is missing"
            RET_F(0)
        END IF    
        ? "L1 = ";L1
        INCR L1
        ?"L1 = ";L1
    END FUNCTION
    
    SUB TestIt02()
      TestIt Const.id3
    
    END SUB

  • #2
    Isn't this kind of the long way to "paying attention whilst programming?"

    Then again, using this techinique you could be producing typical Microsoft Visual Anything-quality applications in no time.
    Michael Mattias
    Tal Systems (retired)
    Port Washington WI USA
    [email protected]
    http://www.talsystems.com

    Comment

    Working...
    X