Real Software Forums
http://forums.realsoftware.com/

Notification Center in RealStudio
http://forums.realsoftware.com/viewtopic.php?f=21&t=46006
Page 1 of 1

Author:  shaosean [ Wed Nov 21, 2012 2:15 am ]
Post subject:  Notification Center in RealStudio

I know this is something that I missed moving from Carbon/Cocoa to RealStudio and I have seen a few other postings in the forum about it as well.. Standing on the shoulders of Paul who wrote the posting at < http://www.rbdevzone.com/2009/09/callbyname-function/ > I managed to hack together something like the Notification Center.. This works well for me and hopefully it helps someone else (feel free to post upgrades to it).. This is 100% RealStudio and works on all three platforms and seems to be pretty quick..

Sub NotificationAddObserver(pObject As Object, pMethodName As String)
DIM tPair As Pair = pMethodName : pObject

if (uNotificationObjects.HasKey(tPair) = FALSE) then
uNotificationObjects.Value(tPair) = pMethodName
end if
End Sub


Sub NotificationBroadcast(pMethodName As String, ParamArray pArgs As Variant)
if (uNotificationObjects <> Nil) then
for each tKey as Pair in uNotificationObjects.Keys
if (tKey.Left = pMethodName) then
DIM tObject As Object = tKey.Right

if (tObject <> Nil) then
DIM tTypeInfo As Introspection.TypeInfo = Introspection.GetType(tObject)
DIM tMethods() As Introspection.MethodInfo = tTypeInfo.GetMethods()

for each tMethodInfo as Introspection.MethodInfo in tMethods
if (tMethodInfo.name = pMethodName) then
tMethodInfo.Invoke tObject, pArgs
exit for tMethodInfo
end if
next
end if
end if
next
end if
End Sub


Sub NotificationRemoveObserver(pObject As Object, pMethodName As String)
if (uNotificationObjects <> Nil) then
for each tPair as Pair in uNotificationObjects.Keys
if (tPair.Left = pMethodName) AND (tPair.Right = pObject) then
uNotificationObjects.Remove tPair
end if
next
end if
End Sub


Private uNotificationObjects As Dictionary

Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/