[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1195
  • Last Modified:

Launching an Adobe PDF using the CreateObject command in FoxPro

I have some simple code on a form to view a PDF file.

The following code is on page 6 of a pageframe.  It is in the dblClick method of a text field on a grid.

loIE = Createobject("internetexplorer.application")
loIE.Visible = .T.

It works beautifully until you move to a different page in the pageframe and then come back.  Then, nothing happens when you double-click on the text field in the grid.  If you exit FoxPro and go back in, it works as before.  Any idea what I'm doing wrong?
2 Solutions
What is the range of the variable loIE?

Why not open the PDF in a webbrowser inside a VFP form?

You can alternately call the PDF to open in default program.

= ExecuteShell(cPDFFileName)

FUNCTION ExecuteShell
LPARAMETERS cFile, cOperation, cDefaultDirectory, cParameters
LOCAL nHwnd, cParameters, cDefaultDirectory, nShowWindow
DECLARE INTEGER ShellExecute IN shell32.dll AS ShellExecute;
      INTEGER nHwnd,;
      STRING @cOperation,;
      STRING @cFile,;
      STRING @cParameters,;
      STRING @cDefaultDirectory,;
      INTEGER nShowWindow
nHwnd = 0
cOperation = IIF(EMPTY(cOperation),'open',cOperation)
cParameters = IIF(EMPTY(cParameters),NULL,cParameters)
cDefaultDirectory = IIF(EMPTY(cDefaultDirectory),'',cDefaultDirectory)
nShowWindow = 1
= ShellExecute(nHwnd, @cOperation, @cFile, @cParameters, @cDefaultDirectory, nShowWindow)
Olaf DoschkeSoftware DeveloperCommented:
On Vista, it doesn't matter what happens with loIE after the internet Explorer exists. But in Windows7 that may differ. I know it does for Excel, Excel quits, if the foxpro variable get's out of scope, eg is redefined or released. A solution is to store loIE in some place that is not released, eg store it as an item of a collection you add to _screen.

Cyril gives you other possible solutions: webbrowser control or ShellExecute.

Bye, Olaf.
HCPCJJ1Author Commented:
Thank you for your responses.  Both were acceptable solutions, however, the problem turned out to be the fact that the grid control was mondified dynamically during the click of the page, and was taking out the Double-Click command once the page came into focus.

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now