New topic: 

Notification Center in RealStudio

<http://forums.realsoftware.com/viewtopic.php?t=46006>

         Page 1 of 1
   [ 1 post ]                 Previous topic | Next topic          Author  
Message        shaosean          Post subject: Notification Center in 
RealStudioPosted: Wed Nov 21, 2012 2:15 am                         
Joined: Mon Aug 15, 2011 10:25 pm
Posts: 225                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             Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 1 post ]      
-- 
Over 1500 classes with 29000 functions in one REALbasic plug-in collection. 
The Monkeybread Software Realbasic Plugin v9.3. 
http://www.monkeybreadsoftware.de/realbasic/plugins.shtml

[email protected]

Reply via email to