Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Locfile() on top - Foxpro?

Posted on 2014-09-12
Medium Priority
Last Modified: 2014-10-03
I have a PRG which runs a top-level form. In the PRG I want to use locfile() to create a reference to a file which will be used in the form. How can I force the locfile() dialog to come up on top?

The application is a COM server (EXE), which is run from a C++ application. When I run it the locfile comes up hidden behind the Calling EXE.
Question by:krhag28
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
LVL 30

Expert Comment

by:Olaf Doschke
ID: 40320828
LOCFILE() is not what you should use, if you want a file dialog. LOCFILE() only falls back to using a dialog as last resort, if it doesn't find a file. Use GETFILE().

Bye, Olaf.

Author Comment

ID: 40320850
GETFILE() has no default folder, but LOCFILE() has, so that's why I prefer LOCFILE(). However the problem with not being on top is the same.
LVL 30

Expert Comment

by:Olaf Doschke
ID: 40320856
a) CD into the desired default folder and GETFILE starts there.
b) GETFILE uses the system open file dialog, which should appear on top always.

You might set the alwaysontop=.f. when your form is started and right before you start LOCFILE or GETFILE.

Bye, Olaf.
Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.


Author Comment

ID: 40321248
a) I prefer not to change the default folder, but of course it is possible...
b) Unfortunately it does not appear on top

No form is started - I run the file open dialog from the main PRG.

My conclusion is that I need to involve a form to force it on top.
LVL 30

Accepted Solution

Olaf Doschke earned 1000 total points
ID: 40321645
>My conclusion is that I need to involve a form to force it on top

You initially said "I have a PRG which runs a top-level form". You also said "In the PRG I want to use locfile() to create a reference to a file which will be used in the form"

You didn't made very clear what you do when, but GETFILE and LOCFILE should display their dialog on top no matter if a VFP form already is shown or not.

You also said "The application is a COM server (EXE)", then you'll have an olepublic class to start it from C++. How about showing your code?

Here's what I tested:
Define Class myclass as custom olepublic
   somefile = ""

   Procedure init()   
      somefile = LocFile("C:\temp\test.txt")
      somefile = GetFile("txt")

Open in new window

Compiled into myapp.exe and registered by compilation.

Started from Word via:
Dim o As Object
   Set o = CreateObject("myapp.myclass")

Open in new window

This displays both dialogs in front if the word document. I'd say you have to figure out where Windows stores defaults/last usage and positioning of the system file open dialog, this is at least not a general misbehaviour of VFP.

Bye, Olaf.

Author Closing Comment

ID: 40360942
The solution is correct, but does not solve my problem. I had to move the opendialog from the prg to a form, then it works.

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
Simple Linear Regression
Introduction to Processes

704 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question