Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Sat Jul 22, 2017 7:51 am
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Notification Center in RealStudio
PostPosted: Wed Nov 21, 2012 2:15 am 
Offline

Joined: Mon Aug 15, 2011 10:25 pm
Posts: 293
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

_________________
Real Studio 2012r1.1 | MacBook Pro i5, 10.6.8 | Windows 7


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group