Sendmessage

BlitzMax Forums/BlitzMax Beginners Area/Sendmessage

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.

It's just a generic interface included in the base object for you to use in any way you wish...

Rem
	SendMessage() (ab)use...
EndRem

Strict

Type TCheese
	Field name$
	Field characteristic$
	
	Method Init:TCheese(name$, characteristic$)
		Self.name$ = name$
		Self.characteristic$ = characteristic$
		
		Return Self
	End Method
	
	Method SendMessage:Object(message:Object, context:Object)
		Select context
			Case "Display"
				Select message
					Case "Name"
						Return ShowName()
					
					Case "Characteristic"
						Return ShowCharacteristic()
				End Select
		End Select
	End Method
	
	Method ShowName$()
		Return name$
	End Method
	
	Method ShowCharacteristic$()
		Return characteristic$
	End Method
End Type

Type TFruit
	Field name$
	Field characteristic$
	
	Method Init:TFruit(name$, characteristic$)
		Self.name$ = name$
		Self.characteristic$ = characteristic$
		
		Return Self
	End Method
	
	Method SendMessage:Object(message:Object, context:Object)
		Select context
			Case "Display"
				Select message
					Case "Name"
						Return ShowName()
					
					Case "Characteristic"
						Return ShowCharacteristic()
				End Select
		End Select
	End Method
	
	Method ShowName$()
		Return name$
	End Method
	
	Method ShowCharacteristic$()
		Return characteristic$ + " and full of fruity goodness..."
	End Method
End Type

Local a:TCheese = New TCheese.Init("Cheddar", "Hard")
Local b:TCheese = New TCheese.Init("Stilton", "Moldy")
Local c:TCheese = New TCheese.Init("Camenbert", "Smelly")
Local d:TFruit = New TFruit.Init("Banana", "Yellow")
Local e:TFruit = New TFruit.Init("Apple", "Red")
Local f:TFruit = New TFruit.Init("Orange", "Err...Orange")

ShowMeTheObject(a)
ShowMeTheObject(b)
ShowMeTheObject(c)
ShowMeTheObject(d)
ShowMeTheObject(e)
ShowMeTheObject(f)

End


Function ShowMeTheObject(obj:Object)
	Print
	Print String(obj.SendMessage("Name", "Display"))
	Print String(obj.SendMessage("Characteristic", "Display"))
End Function