5 |
The LA Fox Developer Newsletter
|
October 1999
|
Communications
(Con’t from page 4)
TYPE(<cVarName>) will return “0”, and ? oVarName will NULL. Some Visual FoxPro BaseClasses support a Release() method (Forms and FormSets), so you can experiment with this without having to create a custom class-based object. notice that in either case, a Release() method leaves the object variable intact, with a TYPE() of “0” and a value of. NULL
Note that unlike the technique of storing the reference name in code listing 5, it is necessary for an object to be instantiated before a reference to it can be stored as another object’s property.
Another point is that one could, if needed, actually instantiate an object as a property of another object. Imagine also an object that has an array property, whose elements are a series of objects!
There is one last special-case, but extremely useful, technique for referencing form objects without having to explicitly name the form you wish to send a message to.
The Visual FoxPro screen is an exposed public object, and based on a subclass of the Visual FoxPro BaseClass “Form”. As such it has all of the members of the ForrnClass, and has a couple of additional properties that can be queried or set (FormCount and Forms). One of the properties the _SCREEN object posesses (courtesy of the Form baseclass) is ActiveForm. If you have several forms open on the FoxPro desktop, another object can determine which one has focus and communicate with that form by referencing the form as:
SCREEN.ActiveForm
So, for example, if you have a toolbar that wants to tell the active form to skip to the next record, it could do so by executing:
SCREEN.ActiveForm.Next()
and the form’s Next() method code would run.
As a further example of the difficulties in determining an object’s reference, and to illustrate the utility of the AciveForm property, try this: Create a form (call it TESTI) using the form designer and save it. Don’t bother adding any controls or anything, just a simple blank form will do. From the command window,
DO FORM TESTI
Drag the form to the upper left of the screen, return to the
command window, and again:
DO FORM TESTI
Drag the second instance of the form to the upper right of the screen and drag the command window until
it
is visible at the bottom. In the command window, type:
|
Testi .BackColor=RGB(O,O,O)
You will observe
that the background of the form in the upper left of the screen becomes black.
Now, try to figure out how to do the same with the form in the upper right, It’s easy if you do:
,SCREEN.ActiveForm.BackCoIorRGB(O,O,O)
However, this is the only way to access the properties of the second instance of Test.SCX! For ways to get around this particular problem, check the Visual FoxPro help file under DO FORM and pay particular attention to the NAME and LINKED clauses.
There is more than one way to skin a cat, and there is clearly more than one way to establish communications between objects, but as the last example above shows, doing so easily and with some flexibility requires some careful forethought. All the techniques described here are very simple, but vary considerably in the advantages, disadvantages, capabilities and limitations that they bring to your class design and development efforts. No one method is “right” for all situations, or even one particular situation, so it will benefit developers to become familiar with all of them. Also, if any of you come up with other methods, I’d sure appreciate hearing about it!
[Ed.Note: Steve Sawyer is Director of Technology for Kirtland
Associates, a company specializing in custom database applications. Steve is a Microsoft Certified Professional, a Microsoft MVP, and a contributing editor forAdvisor Media, editing the monthly Tips Tricks and Traps column in FoxPro Advisor. He is co-author (with Jim Booth) of “EffectWe Techniques forApplication Development with Visual FoxPro 6.0 (Hentzenwerke Publishing, 1998). Steve is a founding member and president of the Detroit Area Fox User Group, and resides in suburban Detroit, Ml.]
[One last Ed.Note: For those of you who missed the first installment, point your browser to the LA Fox website at
hftp://
www.lafox.org
and check out the downloads section for “message.zip”J
Removing Obstacles
(Con’t from page 2)
the text format obstacle, someone wrote a few hundred lines of code to change the new text format to the old text format. So, the new text got converted to the old text, which is then read by low-level file commands. APPEND FROM
...
TYPE SDF and SCAN were too simple, I guess. I spent 3 days trying to map where things came from and went to. By removing the text format obstacle, I got to toss out a bunch of my ugliest code, and now my poor addled brain can understand this stuff.
|
Page 5
|
5 |