How to Pass Data from FoxPro to Another ApplicationLast reviewed: May 17, 1996Article ID: Q117587 |
The information in this article applies to:
SUMMARYApple Events and dynamic data exchange (DDE) are analogous forms of high- level interapplication communication (IAC) provided by System 7 on the Macintosh and by Windows on the IBM-compatible PC, respectively. Microsoft FoxPro for Macintosh does not provide the same level of access to IAC that its Windows counterpart achieves through DDE. While FoxPro for Windows works with a fairly sophisticated set of DDE functions that you can use to set up FoxPro for Windows as a client or a server application, FoxPro for Macintosh works only with the required set of functions (RUN, OPEN, PRINT, QUIT) in addition to DO SCRIPT, allowing you to execute veritably any command in a script that you can execute interactively in the FoxPro Command window. However, a problem arises when you want to pass the result of one of these commands from FoxPro for Macintosh to the client application requesting the data. While the RUNSCRIPT command provides a means for returning a value to FoxPro after an AppleScript script has finished performing an operation or a calculation, the means of passing data to an application from FoxPro is not as straightforward. Since no WITH clause is included with RUNSCRIPT, you cannot simply pass parameters to a script that could then pass the data contained in those parameters to another application. This article explains two methods of passing data to an application that is requesting data from FoxPro. The first method uses primitive file passing; the second uses the Clipboard, also known as the "scrap."
MORE INFORMATION
Method 1As stated above, the DO SCRIPT command allows you to execute virtually any command that you can enter in the Command window. This functionality is fine for performing basic maintenance on a table or for printing a routine report or a set of labels where no result is needed in order to proceed. Often, however, a decision is made based upon information derived from a table. Using DO SCRIPT, you can perform a query to obtain information from a table. However, you cannot directly return the result of the query to the application requesting that the query be performed. One method of circumventing this limitation is to use FoxPro's ability to create ASCII files and in some cases files of the type specific to the application that is requesting the data. The following code presents a simple example of how you can take advantage of FoxPro's ability to store and manage tabular data and Microsoft Excel's ability to analyze that data.
The advantage of the previous approach is that there is practically no limit to the amount of data that can be passed from FoxPro to the requesting application. The disadvantage is that FoxPro must write to a disk file and that file must in turn be read, a much slower means of communication than using RAM. On the Macintosh, the Clipboard is an area in RAM that can be used to provide a faster, although limited, means of passing data and requests between applications.
Method 2Many Macintosh applications, including FoxPro for Macintosh, maintain their own private scrap. FoxPro for Macintosh makes its private scrap available to the user through the system memory variable _CLIPTEXT. When you are switching from one application to another, the suspended application transfers the contents of its private scrap to the system scrap. When an application is resumed, it detects whether or not the contents of the system scrap have changed, and, if necessary, transfers the contents of the system scrap to its own private scrap. Activating one application, the destination, implies that another application, the source, is suspended. In the context of an AppleScript script and the Apple Events from which it is derived, you must issue the "activate" command prior to accessing the Clipboard in order to ensure that the previous application has transferred the contents of its private scrap to the system scrap. The following example shows that the system scrap, and hence the destination application's scrap, will not be updated unless the destination application is activated first. This example assumes that both FoxPro for Macintosh and the Scriptable Text Editor, supplied with the AppleScript extension, are available and that there is enough RAM available to run FoxPro for Macintosh, the Scriptable Text Editor, and a small script simultaneously.
tell application "Scriptable Text Editor" activate -- force the generation of a suspend event in FP for Mac paste end tell -- Return focus to FoxPro tell application "Microsoft FoxPro" activate end tellSave and close the script, and then repeat steps 3, 4, and 5. NOTE: If a substantial amount of data is passed through the Clipboard, the Macintosh operating system may place the data in a temporary file. There is no way to prevent this from happening other than to limit the amount of data passed to the Clipboard. For an in-depth discussion of the Scrap Manager, see "Inside Macintosh: More Macintosh Toolbox." For more information about IAC, see "Inside Macintosh: Interapplication Communication." The Event Manager and its related Suspend and Resume events are discussed in "Inside Macintosh: Macintosh Toolbox Essentials."
REFERENCESMicrosoft Excel "Function Reference," version 4.0 Microsoft Excel "User's Guide 2," version 4.0 Microsoft FoxPro "Installation and Macintosh Features Guide" "AppleScript Developer's Kit," Apple Computer "Inside Macintosh: Interapplication Communication," Apple Computer "Inside Macintosh: More Macintosh Toolbox," Apple Computer
|
Additional reference words: FoxMac 2.50b 2.50c
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |