Theos PowerBasic Museum 2017

Archive => Discussion - Legacy Software (PBWIN 9.0+/PBCC 5.0+) => Topic started by: Paul Breen on August 30, 2008, 11:39:31 PM

Title: objects and dim all
Post by: Paul Breen on August 30, 2008, 11:39:31 PM
I just got the ver 9 and am playing with it. Using Bob Zales' stickies about objects I have a little class (primary school?) that works but only if I do not use "dim all". You can't "dim" the variable in the class code block so what gives? Note that Bob has not used "dim all" in his examples that I can see.

Another hiccup for me is not using the deprecated postfix like temp& for temp as long. Here is my code:


#COMPILE EXE
'#DIM ALL

FUNCTION PBMAIN () AS LONG
    DIM stuff AS myInterface
    DIM x&
    'dim temp&

    LET stuff = CLASS "myClass"
    x& = stuff.bumpit(77)

    MSGBOX STR$(x&)

    x& = stuff.bumpit(x&)
    MSGBOX STR$(x&)

END FUNCTION
'-----------------------------------------------------------------------------
'--------
'-----------------------------------------------------------------------------
CLASS myClass

    'DIM temp AS LONG 'won't compile if decommented
    'DIM temp& 'Requires Procedure
      INSTANCE counter AS LONG
      INTERFACE myInterface
          INHERIT IDISPATCH
          METHOD bumpit(inc AS LONG) AS LONG
            INCR counter
            temp& = counter + inc

            METHOD = temp&
          END METHOD
        END INTERFACE
END CLASS
'-----------------------------------------------------------------------------
'--------
'-----------------------------------------------------------------------------

Title: Re: objects and dim all
Post by: José Roca on August 30, 2008, 11:46:46 PM
 
You can use both #DIM ALL and &. What you can't use is DIM to declare instance variables. You have to use INSTANCE.


#COMPILE EXE
#DIM ALL

FUNCTION PBMAIN () AS LONG
    DIM stuff AS myInterface
    DIM x&

    LET stuff = CLASS "myClass"
    x& = stuff.bumpit(77)

    MSGBOX STR$(x&)

    x& = stuff.bumpit(x&)
    MSGBOX STR$(x&)

END FUNCTION
'-----------------------------------------------------------------------------
'--------
'-----------------------------------------------------------------------------
CLASS myClass

   INSTANCE counter AS LONG
   INSTANCE temp&

   INTERFACE myInterface
      INHERIT IDISPATCH
      METHOD bumpit(inc AS LONG) AS LONG
         INCR counter
         temp& = counter + inc
         METHOD = temp&
      END METHOD
    END INTERFACE

END CLASS
'-----------------------------------------------------------------------------
'--------
'-----------------------------------------------------------------------------