Class extension (dot syntax for new methods)

BlitzMax Forums/BlitzMax Programming/Class extension (dot syntax for new methods)

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

I'm not sure I get what you're after entirely but the way that I add methods is via function fields. This often comes up for me when I am writing a low level class that needs access to higher level functionality e.g. my sprite collection needs to somehow report an error but displaying text is something done higher up by a set of gui classes...


Type Tsprite
Field x,y,id,etc'...
EndType


Type TspriteCollection Extends TList
Field _id:Int
Field error(msg:String)
Method put(s:Tsprite,x:Int,y:Int)
	_id:+1
	s.x=x
	s.y=y
	s.id=_id
	AddLast(s)
EndMethod
Method get:Tsprite(id:Int)
	For Local s:Tsprite=EachIn Self
		If s.id=id Return s
	Next
	If error error("Could not find sprite "+id)
EndMethod
EndType



then in my gui class or higher level whatever I simply set error to something that would take care of that...

Function showError(msg:String)
	Notify(msg)
EndFunction


Global mySprites:TspriteCollection=New TspriteCollection
mySprites.error=showError
mySprites.get(999)


Sorry if I misread what you were after..