Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Calling a form not in focus
Message
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Miscellaneous
Thread ID:
00437475
Message ID:
00437485
Views:
24
>Hi all,
>
>What is the best way to move focus to another form by coding? My application usually has multiple forms opened at the same time. Moreover I sometimes have to call a function from another form while working in another. How to refer to a form that is not in the focus?
>

First, you need an object reference to the Form you want to access; obviously, the thisform is not going to work. Most frameworks implement a Form manager of some sort that will permit you to examine the instanced forms presently controlled by the app; the Form manager would pass you back an object reference to the Form you want to access. Once you have an object reference to another Form (for ease of reference, I'll call it oFormObj), it's easy enough to locate a Control in the Form's Controls collection, and issue a oFormObj.Controls(nControlIndex).SetFocus(), or issue a call to the form object's oFormObj.Show() method.

You can invoke a method or access a property of another Form without making it active; ie OFormObj.Name returns the name of the Form oFormObj; a statement like

nMyReturnVar = oFormObj.CustomMethod(parm1, parm2)

invokes the method with the parameters passed, returning a result, without necessarily making oFormObj the active Form. Typically, if you're doing this a great deal, it's a strong indication of a flawed OO analysis; since the two forms are tightly coupled, and accidents, such as failing to release the temporary object reference to the other form may result in dangling object references, which can cause all sorts of problems. My general approach is to not return an object ref from my Form Manager, but to identify the Form to be dispatched, and have my Form manager actually be the only object that dispatches Form instances - it ensures that all my Forms are managed in a single place, and the Form manager object, a part of my application framework, is responsible for controlling the lifespan of my Forms and avoiding the dangling reference issues.

>Thanks in advance.
EMail: EdR@edrauh.com
"See, the sun is going down..."
"No, the horizon is moving up!"
- Firesign Theater


NT and Win2K FAQ .. cWashington WSH/ADSI/WMI site
MS WSH site ........... WSH FAQ Site
Wrox Press .............. Win32 Scripting Journal
eSolutions Services, LLC

The Surgeon General has determined that prolonged exposure to the Windows Script Host may be addictive to laboratory mice and codemonkeys
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform