Assigning a function reference to a type field.

BlitzMax Forums/BlitzMax Programming/Assigning a function reference to a type field.

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.

Ok. I'm trying to do mine in a slightly different order (maybe that's what has me confused). Here's how I'm trying to do it (with just the important stuff reproduced):

In my main file I have a call to create the instance of the type, a function call to pass the pointer into the self-contained type, and the function to be passed:

Strict
Include "RZone.bmx"  'my zones file... the part I want to be modular 

Graphics 800,600


Global c_Zone:r_zone = New r_zone

c_zone.Create(0,20,0,20,LabelIT())  'sets the boundary of the zone and passes the function to initiate on a left-click

While (Not KeyHit(KEY_ESCAPE))

Cls
r_zone.CheckZones()  'checks to see if any zones are activated

Flip
Wend

Function LabelIt:Int()  'my function I want to use for a left-click
	DrawText ("Activated",MouseX(),MouseY())
End Function


Then, in my RZone.bmx (I'm trying to keep this segregated and modular) I have the type declaration, the method to create each instance of the type, the method to call the assumed function, and the code to check whether it's time for the assumed function to be called:
Type r_zone
	Field x1#,x2#  'x location of the zone and its width
	Field y1#,y2#  'y location and width
	Field zone_number  'used for indexing
	Field left_clicked:Byte Ptr  'the pointer to use for the assumed function

	Global r_ZoneList:TList  'for my list/cycle

'********************** Create Zone *****************

	Method Create (a1#,a2#,b1#,b2#,fun1:Byte Ptr)  'gets the zone dimensions and the function to call on a left-click
			Local temp_zone:r_zone = New r_zone  'temp instance to use for setup
			temp_zone.x1 = a1
			temp_zone.x2 = a2
			temp_zone.y1 = b1
			temp_zone.y2 = b2
			temp_zone.left_clicked = fun1  'this should get the pointer to the function for left-click!
			If r_ZoneList = Null Then r_ZoneList = CreateList()
			r_ZoneList.AddLast(temp_zone)

	End Method

'********************** Check Zones ******************

	Function CheckZones()  'I send this into a method so that it is protected from outside influences 
		For Local test:r_zone = EachIn r_ZoneList
			test.Check(MouseX(),MouseY(),MouseHit(1))
		Next
	End Function	
	
'********************** Check ************************

	Method Check(a#,b#,but1)  'My method to check if the mouse is in the zone and the left button down
		If a>= x1 And a<= x2 And b>= y1 And b<= y2 Then
			If but1 >0 Then If_leftclicked()
		End If
	End Method

'********************Left Click*********************
	
	Method If_Leftclicked:Int()
	Local locfun1:Int() = left_clicked
	End Method

End Type

My problem comes when I try to pass the pointer from the main file through a parameter in the Create() Method. Is there any way to do that?

Thanks again for all your help. Get back to me at your leisure... I would hate to be the cause of any domestic infelicity! *grin*