Namespace System


Class _SimpleDelegate
Public
	hasThisPtr As Boolean
	object As Object
	methodPtr As VoidPtr

	Sub _SimpleDelegate( object As Object, methodPtr As VoidPtr )
		This.hasThisPtr = True
		This.object = object
		This.methodPtr = methodPtr
	End Sub
	Sub _SimpleDelegate( methodPtr As VoidPtr )
		This.hasThisPtr = False
		This.object = Nothing
		This.methodPtr = methodPtr
	End Sub

	Function IsEqual( sd As _SimpleDelegate ) As Boolean
		Return ( This.hasThisPtr = sd.hasThisPtr and ObjPtr(This.object) = ObjPtr(sd.object) and This.methodPtr = sd.methodPtr )
	End Function
End Class

Class DelegateBase
Protected
	simpleDelegates As System.Collections.Generic.List<_SimpleDelegate>

	Sub _Add( dg As DelegateBase )
		If Not ActiveBasic.IsNothing(dg) Then
			Dim i As Long
			For i=0 To ELM(dg.simpleDelegates.Count)
				simpleDelegates.Add( dg.simpleDelegates[i] )
			Next
		End If
	End Sub

	Sub _Delete( dg As DelegateBase )
		If Not ActiveBasic.IsNothing(dg) Then
			Dim i As Long
			For i=0 To ELM(This.simpleDelegates.Count)
				Dim i2 As Long
				Dim isExist = False
				For i2=0 To ELM(dg.simpleDelegates.Count)
					If This.simpleDelegates[i].IsEqual( dg.simpleDelegates[i2] ) Then
						isExist = True
					End If
				Next
				If isExist Then
					This.simpleDelegates.RemoveAt( i )
				End If
			Next
		End If
	End Sub

Public
	Sub DelegateBase()
		simpleDelegates = New System.Collections.Generic.List<_SimpleDelegate>()
	End Sub

/*
	Sub Operator + ( sd As System._SimpleDelegate )
		Add( sd )
	End Sub*/
Public
End Class


End Namespace


Function _System_CreateSimpleDynamicDelegate( object As Object, methodPtr As VoidPtr ) As System._SimpleDelegate
	Return New System._SimpleDelegate( object, methodPtr )
End Function
Function _System_CreateSimpleStaticDelegate( methodPtr As VoidPtr ) As System._SimpleDelegate
	Return New System._SimpleDelegate( methodPtr )
End Function
