Board,
is there a way to create my own delegates (or btw: events) for my own classes? Or is this only possible if I use ObjC?
Regards
Udo
udo.killermann wrote:Board,
is there a way to create my own delegates (or btw: events) for my own classes? Or is this only possible if I use ObjC?
Regards
Udo
Declare Class "NSBezierPath"
Declare Sub "NSBezierPath" - (void)fill
Declare Sub "NSBezierPath" + (void)fillRect:(NSRect)aRect
Declare Function "NSBezierPath" + (NSBezierPath)bezierPathWithRect:(NSRect)aRect
Declare Sub "NSColor" - (void)set
Declare Event "Scroller" - (void)mouseDown:(NSEvent *)theEvent
Event mouseDown(theEvent As NSEvent)
Alert("mouseDown", Info(theEvent))
End Event
Event DrawRect(Argument As Rect)
' do drawing here
Dim r As Rect
Dim bp As NSBezierPath
Dim colour As NSColor = BlueColor
r = Rect(10.0, 10.0, 50.0, 60.0)
bp = NSBezierPath.bezierPathWithRect(r)
' colour = BlueColor
colour.set()
bp.fill()
End Event
' declare delegates are valid for the entire project
Declare Delegate "NSTableView" - (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
Declare Delegate "NSTableView" - (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView
Declare Delegate "NSTableView" - (void)tableView:(NSTableView *)aTableView setObjectValue:(id)anObject forTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
IBOutlet table As NSTableView
Dim a As Array("a", "b", "c")
Delegate tableView(aTableView As NSTableView, aTableColumn As NSTableColumn, rowIndex As Integer) As id
Return a.Object(rowIndex)
End Delegate
Delegate numberOfRowsInTableView(aTableView As NSTableView) As Integer
Return a.Count()
End Delegate
Delegate tableView(aTableView As NSTableView, anObject As id, aTableColumn As NSTableColumn, rowIndex As Integer)
a.Replace(anObject, rowIndex)
End Delegate
- That's the thing I am looking for. In Objective C a protocol is used to define the interface between caller and callee. How would I do this in ObjB?Applying those declare statements to your own classes is possible as well.
udo.killermann wrote:Bernd,- That's the thing I am looking for. In Objective C a protocol is used to define the interface between caller and callee. How would I do this in ObjB?Applying those declare statements to your own classes is possible as well.
The other usage scenarios of Delegates work well in my own code.
Kind regards
Udo
Delegate calc(arg As Integer) As Integer
Function callMe(what As Integer) As Integer
Dim ret As Integer
ret = calc(what)
Return(ret)
End Function
udo.killermann wrote:Bernd,
in the good old days of Apple-Basic there was "def fn" as a way to define a math function function in one place that you could refer to within your code. I was thinking about building a class the iterates over an interval and evaluates a user supplied function. I thought a delegate would be a nice facility to to so - but I am stuck and don't know how to start this.
I was thinking to define a Delegate (function prototype) inside the class and calling this Delegate within the class. The concrete function should be supplied by the programmer using my class.
- Code: Select all
Delegate calc(arg As Integer) As Integer
Function callMe(what As Integer) As Integer
Dim ret As Integer
ret = calc(what)
Return(ret)
End Function
As most of the time the problem seems to be layer 8 (user) related regarding to the ISO 7 layer model
Regards
Udo
Return to Objective-Basic (Xcode 3)
Users browsing this forum: No registered users and 1 guest