if you design a custom class, instantiate it and then want to Log the properties of its instance. You will come up with Log(theInstance). But instead of logging the properties this statement just logs the class name and memory location of the instance. In order to get what you want, you need to implement a description function that returns a string to represent the internal state.
OK - here comes the code (UKObject.NSObject)
- Code: Select all
Declare Class "NSNumber"
Declare Function "NSNumber" - (NSString *)description
Declare Function "String" - (NSString *)description
Dim amount As NSNumber
Dim name As String
Function amount() As NSNumber
Return amount
End Function
Sub setAmount(theAmount As NSNumber)
amount=theAmount
End Sub
Function name() As String
Return name
End Function
Sub setName(theName As String)
name=theName
End Sub
' this function needs to be defined if we want to log more than
' the name of the class
'
Function description() As String
Return(Concat("{",amount.description(),", ",name.description(),"}"))
End Function
The magic is done in the last lines.
If you now create an instance (e.g. inside Globals's AwakeFromNib):
- Code: Select all
Dim myObject1 As UKObject
myObject1.setAmount(47)
myObject1.setName("Karl")
Log(myObject1) ' or Alert(myObject1)
the last line should log its state and not the generic information shown before.
Stay tuned
Udo