Xojo Conferences
MBSSep2018MunichDE
XDCMay2019MiamiUSA

Platforms to show: All Mac Windows Linux Cross-Platform

/MacCocoa/KeyValueObserver
Function:
Required plugins for this example: MBS MacBase Plugin, MBS Main Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacCocoa/KeyValueObserver
This example is the version from Sun, 13th Apr 2013.
Project "KeyValueObserver.rbp"
Class App Inherits Application
Const kEditClear = "&Löschen"
Const kFileQuit = "Beenden"
Const kFileQuitShortcut = ""
End Class
Class Window1 Inherits Window
Control List Inherits Listbox
ControlInstance List Inherits Listbox
End Control
Control TextField1 Inherits TextField
ControlInstance TextField1 Inherits TextField
End Control
Control PushButton1 Inherits PushButton
ControlInstance PushButton1 Inherits PushButton
EventHandler Sub Action() w.title = TextField1.text End EventHandler
End Control
Control Label1 Inherits Label
ControlInstance Label1 Inherits Label
End Control
EventHandler Sub Open() w = new NSWindowMBS(self) n = new MyNSKeyValueObserverMBS(w.Handle) n.list = list dim options as integer = n.kOptionInitial+n.kOptionOld+n.kOptionNew n.addObserver "frame", options n.addObserver "title", options n.addObserver "firstResponder", options End EventHandler
Property n As MyNSKeyValueObserverMBS
Property w As NSWindowMBS
End Class
MenuBar MenuBar1
MenuItem FileMenu = "&Ablage"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Bearbeiten"
MenuItem EditUndo = "&Rückgängig"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "&Ausschneiden"
MenuItem EditCopy = "&Kopieren"
MenuItem EditPaste = "&Einfügen"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "&Alles auswählen"
End MenuBar
Class MyNSKeyValueObserverMBS Inherits NSKeyValueObserverMBS
EventHandler Function observedValueForKeyPathChanged(keyPath as string, target as variant, change as dictionary, context as variant) As boolean dim kind as integer = change.Lookup(me.NSKeyValueChangeKindKey, -1) dim newValue as Variant = change.lookup(me.NSKeyValueChangeNewKey, nil) dim oldValue as Variant = change.lookup(me.NSKeyValueChangeOldKey, nil) dim newString as string dim oldString as string if newValue isa NSWindowMBS then dim w as NSWindowMBS = newValue newString = "window with title "+w.title elseif newValue isa NSViewMBS then dim v as NSViewMBS = newValue newString = "view of class "+v.className else newString = newValue.StringValue end if if oldValue isa NSWindowMBS then dim w as NSWindowMBS = oldValue oldString = "window with title "+w.title elseif oldValue isa NSViewMBS then dim v as NSViewMBS = oldValue oldString = "view of class "+v.className else oldString = oldValue.StringValue end if if oldString = "" then oldString = "nothing" end if select case kind case me.kChangeInsertion list.AddRow keyPath+" inserted "+newString case me.kChangeRemoval list.AddRow keyPath+" removed "+oldString case me.kChangeReplacement list.AddRow keyPath+" changed from "+oldString+" to "+newString case me.kChangeSetting list.AddRow keyPath+" set from "+oldString+" to "+newString end Select Return true End EventHandler
Property list As listbox
End Class
End Project

Feedback, Comments & Corrections

The items on this page are in the following plugins: MBS MacCocoa Plugin.





Links
MBS FileMaker Plugins