04-23-2005, 02:00 AM
as soon you start uncomment the me.cubed or me.timesX it crashes...
Code:
'
' An OOP-like demo.
' thanks to David of xblite
'
TYPE OOPLIKE
var AS LONG
squared AS FUNCTION (this as OOPLIKE) as integer
cubed AS FUNCTION (this as OOPLIKE) as integer
timesX AS FUNCTION (this as OOPLIKE, byval x as integer) as integer
END TYPE
DECLARE FUNCTION Initialize (byval b as integer) as OOPLIKE ptr
DECLARE FUNCTION Squared (this as OOPLIKE ) as integer
DECLARE FUNCTION Cubed (this as OOPLIKE) as integer
DECLARE FUNCTION TimesX (this as OOPLIKE, byval x as integer) as integer
' start
dim SHARED as OOPLIKE me, you
me = *Initialize (3)
you = *Initialize (5)
PRINT "================="
PRINT "me.var " ; me.var
PRINT "me.squared " ; me.squared (me)
' PRINT "me.cubed " ; me.cubed (me)
' PRINT "me.timesX " ; me.timesX (me, 100)
PRINT "================="
PRINT "you.var " ; you.var
PRINT "you.squared " ; you.squared (you)
' PRINT "you.cubed " ; you.cubed (you)
' PRINT "you.timesX " ; you.timesX (you, 100)
PRINT "================="
PRINT "Changing .var in me and you"
me.var = 6
you.var = 7
PRINT "================="
PRINT "me.var " ; me.var
PRINT "me.squared " ; me.squared (me)
' PRINT "me.cubed " ; me.cubed (me)
' PRINT "me.timesX " ; me.timesX (me, 100)
PRINT "================="
PRINT "you.var " ; you.var
PRINT "you.squared " ; you.squared (you)
' PRINT "you.cubed " ; you.cubed (you)
' PRINT "you.timesX " ; you.timesX (you, 100)
PRINT "================="
INPUT "press ENTER to exit..." ,pause
END
'
'
' ###########################
' ##### Initialize () #####
' ###########################
'
FUNCTION Initialize (byval b as integer) as OOPLIKE ptr
dim this as OOPLIKE
this.var = b
this.squared = @Squared ()
this.cubed = @Cubed ()
this.timesX = @TimesX ()
RETURN @this
END FUNCTION
'
'
' ########################
' ##### Squared () #####
' ########################
'
FUNCTION Squared (this as OOPLIKE) as integer
RETURN this.var * this.var
END FUNCTION
'
'
' ######################
' ##### Cubed () #####
' ######################
'
FUNCTION Cubed (this as OOPLIKE) as integer
RETURN this.var * this.var * this.var
END FUNCTION
'
'
' #######################
' ##### TimesX () #####
' #######################
'
FUNCTION TimesX (this as OOPLIKE, byval x as integer) as integer
RETURN this.var * x
END FUNCTION