Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Object Spy
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Titre:
Divers
Thread ID:
00896696
Message ID:
00896723
Vues:
17
>You could probably use AEVENTS to grab an object reference to the object >that was the event source, then tack on it's "Class" property into your >output to get the results you want.

Nice idea. I think I'd have to stick with a one-to-one relationship between spy and object, but that might have some up sides anyway...

Nice thing about AEVENTS() is you can inspect the runtime state of the watched object without actually hooking up a reference to it (which would have some GC implications).

Thanks,
-lc
PS: You are on the "mocha owed" list <s>
loB=createobject([Bindtest])
loCIA=createobject([SpyAgency])

loCIA.watch(m.loB)

*-- fire the method of interest
loB.method1([foo],1)

*=====================================
define class BindTest as Relation
*=====================================
  function method1( tcParam1, tnParam2 )
    debugout [method1 daring do here]
    
    *-- try a little recursion
    if m.tnParam2<3
      this.method1(tcParam1,tnParam2+1)
    endif
        
enddefine

*=====================================
define class SpyAgency as custom
*=====================================
add object oSpys as collection

function watch( toObject )
  local loSpy, laMembers(1), lnMembers
  loSpy = createobject( [spook] )
  
  *[[ consider data-driven include/exclude lists here
  lnMembers = amembers(laMembers,m.toObject,1)
  for lnK = 1 to m.lnMembers
    *[[need to think about member objects here too
    *[[ maybe we could just hook a reference to toObject on loSpy here?
    if laMembers(m.lnK,2) $ "Event, Method" 
      bindevent(toObject,laMembers(m.lnK,1),loSpy,[start])
      bindevent(toObject,laMembers(m.lnK,1),loSpy,[end],1)
    endif
  endfor
  
  this.oSpys.add( m.loSpy )
endfunc
enddefine

*=====================================
define class Spook as Relation
*=====================================  

  function start( p1,p2,p3,p4,p5,p6,p7,p8,p9 )
    local laStack(1), lnDepth, laEvents(1)
    lnDepth = astackinfo( laStack )
    aevents( laevents, this )
    debugout [start: ]+laevents(1,2).class+[::]+getwordnum(laStack(m.lnDepth-1,6),2,[.(])
    
  function end( p1,p2,p3,p4,p5,p6,p7,p8,p9 )
    local laStack(1), lnDepth, laEvents(1)
    lnDepth = astackinfo( laStack )
    aevents( laevents, this )
    debugout [end: ]+laevents(1,2).class+[::]+getwordnum(laStack(m.lnDepth-1,6),2,[.(])
    
enddefine
Which returns:

start: Bindtest::method1
method1 daring do here
start: Bindtest::method1
method1 daring do here
start: Bindtest::method1
method1 daring do here
end: Bindtest::method1
end: Bindtest::method1
end: Bindtest::method1


And obviously, I'd have options to get more info from the watched object as well.
-lc
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform