Blitz3D had the command Str, which could do what you wanted.
; Blitz3D code
Type test
Field num
End Type
testa.test = New test
testa\num = 5
Print Str testa
WaitKey()
This prints "[5]".
; b3D code with Compare function
Type test
Field num
End Type
testa.test = New test
testb.test = New test
testa\num = 5
testb\num = 6
Print Str testa
Print Compare(testa, testb)
WaitKey()
Function Compare(o1.test, o2.test)
o3$ = Str o1
o4$ = Str o2
If o3 = o4 Then Return True Else Return False
End Function
Unfortunately, this doesn't work in BMax.
Str creates a string, with all contents of all fields in the object, separated by comma's and between [].
This could be another thing that could be added to BMax.
Then you would just compare both outputs of the Str function to see if they match.
Try the above code in B3D and change the line "testb\num = 6" into "testb\num = 5" and see what it does.
This would be what you want, KamaShin.
This code (in BMax) does what you need (thanks to the idea of teamonkey):
Type test
Field num%
Field text$
Method Compare(o1:Object)
' Try to cast the given object to this object-type
o2:test = test(o1)
' If casting was succesfull (the object passed is a "test"-instance)
If o2 Then
' Compare all fields
If (num = o2.num) And (text = o2.text) Then Return True Else Return False
Else
Return False
EndIf
End Method
End Type
testa:test = New test
testb:test = New test
testa.num = 5
testa.text = "Hello"
testb.num = 7
testb.text = "Hello"
Print testa.Compare(testb)
Play with the field-value a bit and see.
This code will have to be changed everytime you add a new field to the type "test", that's the downside of it (compared to the B3D code).
But it could be a problem when the passed object to the Compare-method is a derived type of "test".
Then there would be more fields inside your object and this method only checks the fields specific to the "test"-type.