Un-Mapping Mapped Network Drives Andrew Coates - dFPUG-Portal
Un-Mapping Mapped Network Drives Andrew Coates - dFPUG-Portal
Un-Mapping Mapped Network Drives Andrew Coates - dFPUG-Portal
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
THIS.aForms[lnNewRow, 3] = loObject<br />
RETURN<br />
ENDPROC<br />
PROCEDURE RemoveForm<br />
LPARAMETERS tuParm1, tcParmType<br />
*-- This method would allow a single form to<br />
*-- be removed from the collection. The<br />
*-- first parameter could be an object<br />
*-- reference, an index position within the<br />
*-- collection, a form name, or even a caption.<br />
*-- When the form is removed, the array<br />
*-- containing the collection would be<br />
*-- adjusted. If the last form in the<br />
*-- collection is removed, the first position<br />
*-- in the collection array would be set to<br />
*-- .F. to indicate an empty collection.<br />
ENDPROC<br />
PROCEDURE RemoveAllForms<br />
*-- This method would allow all forms to be<br />
*-- removed from the collection. The<br />
*-- GetFormCount method would be used<br />
*-- to determine the number of forms in the<br />
*-- collection, and this method would iterate<br />
*-- through them to call the<br />
*-- .RemoveForm method for each.<br />
ENDPROC<br />
PROCEDURE GetFormRef<br />
LPARAMETERS tuParm1, tcParmType<br />
*-- This method returns a reference to the<br />
*-- form indicated by the passed parameters.<br />
*-- The parameter might be a class name, an<br />
*-- index position within the collection,<br />
*-- a caption, or some other form-specific<br />
*-- property. The FindForm method would be<br />
*-- used to find the matching form row<br />
*-- within the collection. If there's no<br />
*-- matching form found, NULL would be<br />
*-- returned.<br />
ENDPROC<br />
ENDDEFINE<br />
The idea behind this class definition is that the Forms<br />
Manager would always be available to the open forms in<br />
the application. This is often handled by making the<br />
Forms Manager itself a member of the omnipresent<br />
“application object.” Because the Forms Manager is<br />
always available, the forms in the application can add<br />
themselves to it when instantiating and remove<br />
themselves from it during the destruction process. For<br />
example, the following code would be placed into a base<br />
form class’s Init() event to automate the process of adding<br />
a new form to the collection:<br />
oApp.oFormsManager.AddForm(THISFORM)<br />
When the form is being closed, the following line<br />
of code in the form’s Destroy() event would prompt<br />
the Forms Manager to remove the closing form from<br />
the collection:<br />
oApp.oFormsManager.RemoveForm(THISFORM)<br />
Obviously, the preceding example code isn’t a<br />
complete Forms Manager solution, but it illustrates a<br />
variety of reasons that a Forms Manager’s functionality<br />
would be beneficial. Because you could get an object<br />
reference to any specific form in the collection, you could<br />
always communicate with the precise form you need in<br />
any situation. If that form isn’t available, the Forms<br />
Manager can indicate this as well so that you can<br />
proceed accordingly.<br />
Example 2—the dialog box<br />
Another problem that the Mediator pattern helps to<br />
solve is the issue of communications between reusable<br />
containers that are conditionally appearing in yet another<br />
container. Most dialog boxes contain interface elements<br />
that are used throughout an application. For example, a<br />
file-selection dialog box contains a directory list box, but<br />
the dialog box is hardly the only need for that control.<br />
Also, dialog boxes usually have controls that turn on/off<br />
or become enabled/disabled, based on the conditions and<br />
state of other controls in the dialog box. For example, if<br />
the user absolutely must choose a file, then the “OK”<br />
button would be disabled until the user has selected a file.<br />
Obviously, dealing with all these layers of<br />
communication can become a problem, especially if the<br />
same control/container appears in a variety of dialog boxstyle<br />
interfaces. Enter the Mediator pattern as an elegant<br />
solution. By providing a single point of interface for all<br />
the controls in the dialog box, the problem of changing<br />
the state of other controls becomes centralized.<br />
The dialog box shown in Figure 2 is a simple example<br />
of a window that contains three different containers. Each<br />
of the containers provides a mechanism for setting a value<br />
to on or off, while only two of them provide a mechanism<br />
for displaying the current state of that value.<br />
The key here is that the dialog box can have any<br />
number of similar containers added to it without a change<br />
to anything else. That is, none of the other controls in this<br />
dialog box would require changes, nor would the dialog<br />
box itself, which is serving as the Mediator component in<br />
this case.<br />
Each of the containers in the window has two<br />
methods that allow it to interact with the dialog box.<br />
These are UpdateMediator() and SetControls(), which<br />
respectively communicate with the mediator to reflect a<br />
change in state and receive messages from the mediator to<br />
update their member controls. For example, the container<br />
with the check boxes contains the following<br />
UpdateMediator() code:<br />
Figure 2. A simplified dialog box that allows for setting a formwide<br />
value either on or off. While three of the containers can set<br />
the value, only two display its current state.<br />
8 FoxTalk December 1998<br />
http://www.pinpub.com