KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Using AP ShellExecute to open files outside of 4D instead of AP Sublaunch
PRODUCT: 4D Pack | VERSION: | PLATFORM: Mac & Win
Published On: March 14, 2003
Your current browser may not allow you to download the asset. We recommend Mozilla Firefox or Google Chrome.
Log In

Version: 4D 6.8.2

If you have a database that needs to open an external application when an event is handled, you can use the AP ShellExecute command instead of the AP Sublaunch command. The bottom line is that both of these commands enable you to launch an external application. However, only AP ShellExecute will allow you to launch the application by just passing in the file name to open. You may think of AP ShellExecute as an optimized form of AP Sublaunch.

In my database, I have a text field containing the path to an Acrobat file associated to each record in the table. In my form I have a button that when clicked, will launch the file with the correct application.

Here is the way this can be accomplished using AP Sublaunch:


`Method: Using AP Sublaunch
C_TEXT($file;$app)
C_LONGINT($err)
$file:="C:\Documents and Settings\Database-test\testPDF\pub71.pdf"
$app:="C:\Program Files\Adobe\Acrobat 5.0\Reader\AcroRd32.exe"
$err:=AP Sublaunch ($app+" "+$file;0)


The problem here is that when the application used to open the file no longer exists in the directory above, the file will fail to open. On the other hand, using AP ShellExecute, this does not happen. All you have to do is to pass in the file name or the absolute path of the file to open. AP ShellExecute will allow the operating system to handle the execution of the associated application for that file.

Here is how AP ShellExecute launches the PDF file:


`Method: Using AP ShellExecute
C_TEXT($file)
$file:="pub71.pdf"
$err:=AP ShellExecute ($file)


Note: For the MacOS 9 and MacOS X platforms, the file needs to be located at the 4D app level. This means it should be stored within the package. In this situation, simply create an alias to the file, and place this alias next to the application.