The following demonstrates how to launch an application using the execute() command. It also demonstrates a technique for checking if the application is already running before launching it. This is particularly handy when working with DDE and OLE.
Using execute()
To launch an application in Paradox is easy. For example, the following code from the pushButton event of a button launches Notepad.
method pushButton(var eventInfo Event)
execute("NOTEPAD.EXE", No, ExeShowNormal)
endMethod
Checking if the application is already open first
To check if an application is running, you can use the enumWinowNames method to list all the running applications within a table. Then use a scan loop with locatePattern to check if the application is running. To make sure the temporary table is not in conflict with other users in a multi-user situation, create the table in each users private folder.
For example:
enumWindowNames(":priv:mytemptable.db")
Clean Up
To automate the cleanup of the temporary table in your private folder, name the table starting with two underscores. Paradox automatically deletes all files in your private folder that start with two underscores whenever Paradox exits.
For example:
enumWindowNames(":priv:__mytemptable.db")
Complete Example
The following code from the pushButton event of a button checks if Microsoft Word is already running and if it is NOT, then launches it. If Word is running, Word is not launched.
method pushButton(var eventInfo Event)
var
sTable String
tcApps TCursor
lWordOpen Logical
endVar
errorTrapOnWarnings(True)
sTable = ":priv:__apps.db"
enumWindowNames(sTable)
tcApps.open(sTable)
lWordOpen = False
scan tcApps
for tcApps.locatePattern("WindowName",
"..Microsoft Word.."):
lWordOpen = True
quitloop
endScan
if not lWordOpen then
execute("D:\\Program Files\\Microsoft Office" +
+ "\\Office\\WINWORD.EXE",
No, ExeShowNormal)
endIf
endMethod
You can use a technique similar to the above code to find the window name to search for during your scan loop. For example, the following code from the pushButton event of a button displays a table of all Windows. Just make sure the application you want to search for is running prior to executing this code.