Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Binding to ActiveForm

Status
Not open for further replies.

TamarGranor

Programmer
Jan 26, 2005
2,484
US
Hi, guys, got an interesting one here. I'm trying to adjust something everytime a different form is activated without having to put code in the form class. (Trying to do an observer kind of thing.) I figured I'd bind to changes to _SCREEN.ActiveForm, but it doesn't seem to work. Here's my test code:

Code:
ON KEY LABEL f12 clear events

o=CREATEOBJECT("TestBind")
BINDEVENT(_vfp,"ActiveForm",o,"HandleEvent")

o1=CREATEOBJECT("form")
o1.Name = "FirstForm"
o1.Caption = "First"
o1.Show()

o2=CREATEOBJECT("Form")
o2.Name = "SecondForm"
o2.Caption = "Second"
o2.show()

READ EVENTS

RETURN
 
DEFINE CLASS TestBind AS Custom

PROCEDURE HandleEvent

DEBUGOUT PROGRAM()

ENDPROC

ENDDEFINE

Any suggestions? For that matter, I'll really want to do this when using a top-level form as my background, so ideas about what I can bind to there would be helpful.

Tamar
 
How about if after creating the form objects you were to loop through EACH form of _SCREEN. the active forms and bind the event at that time?
Code:
FOR EACH oForm IN _screen.forms 
   BINDEVENT(oForm ,"Activate",o,"HandleEvent")
ENDFOR

-Dave Summers-
[cheers]
Even more Fox stuff at:
 
Egads. My fingers got ahead of my brain. Let me rephrase that.

How about if after creating the form objects you were to loop through EACH form of _SCREEN and bind the event at that time?
Code:
ON KEY LABEL f12 clear events

o=CREATEOBJECT("TestBind")
*BINDEVENT(_screen,"Activate",o,"HandleEvent")

o1=CREATEOBJECT("form")
o1.Name = "FirstForm"
o1.Caption = "First"
o1.Show()

o2=CREATEOBJECT("Form")
o2.Name = "SecondForm"
o2.Caption = "Second"
o2.show()

[COLOR=blue]FOR EACH oForm IN _screen.forms 
   BINDEVENT(oForm ,"Activate",o,"HandleEvent")
ENDFOR [/color]

READ EVENTS

RETURN
 
DEFINE CLASS TestBind AS Custom

PROCEDURE HandleEvent

DEBUGOUT PROGRAM()

ENDPROC

ENDDEFINE

-Dave Summers-
[cheers]
Even more Fox stuff at:
 
What I was looking for was a generic way to handle this no matter how many forms are involved or where they're started. After seeing replies here and on the UT that made it clear that I wasn't just missing something stupid, I decided that for my purposes, it's okay if this only works within the framework.

So, I added a property to the app object, oActiveForm, and added code to the base form class that binds its Activate and Deactivate method to an app object method that resets oActiveForm. With that in place, I can have code anywhere else in the framework that binds to a change in goApp.oActiveForm.

Tamar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top