Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't execute without program 4

Status
Not open for further replies.

TheLazyPig

Programmer
Sep 26, 2019
95
PH
Hi!

I have created a simple project with a form without a prg file then I build it. But when I run the .exe file nothing happens there's no error. Then I create a main.prg file still nothing happens.

main.prg

Code:
DO FORM main
READ EVENTS

Thank you!
 
Did you set this program to be main?


Borislav Borissov
VFP9 SP2, SQL Server
 
In your first attempt, your EXE will have correctly launched the form. But the form will be modeless, which means that as soon as it is launched, it doesn't wait for user interaction. Execution continues, but since there is nothing left to be executed, the EXE finishes, leaving nothing visible on the screen. In other words, the form appears, and then disappears immediately.

In your second attempt, it is possible that - as Borislav suggested - you didn't set MAIN.PRG to be the main program. You do that by right-clicking on the PRG in the project manager and selecting "Set main". If you didn't do that, the form will still be the main program, and the result will be exactly as in the first case.

Another possibility is that you have a CONFIG.FPW file that contains the line SCREEN=OFF. This is not unusual. It is often used to hide the outer VFP window while an app is running. If that's the case, then your program is in fact running correctly, but it is invisible. You can check that by looking for it in the Task Manager. In that case, the solution is simply to remove the offending line from the Config file.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
You're almost there, thanks to Borislav and Mike.

I'll just want to show it visually:
If your first project file i the form, then it becomes bold, like this, right?
mainform_doisvf.png


Now you likely searched and found threads telling of a main.prg, so you created one, right?
minprg_oekpft.png


The secret is neither the bolding nor the name, the bolding tells what in the project is main, but the way to set it is using context menus.
Context menus are underrated if not even known, and if you tell a strict keyboard user to use the mouse rightclick you even get fierce responses, while there also is a key one or two keys right of the spacebar that's the context menu key.

In short, here's that screenshot:
setmain_o5n7ch.png


That's what you use. Or you go into the project menu...
setmain2_uywvxi.png

Anyway you do it, you see now the prg is bold and the scx isn't anymore:
mainall_sdigdf.png


And now welcome to the usage of a main.prg. Everybody talks about this, nobody uses anything else as main project file. It's our C legacy.
And just by the way, you can also receive parameters that can be passed as command line parameters to your exe, simply by adding LPARAMETERS in the main.prg first line. Then what's good is establishing what should happen in the event of errors with ON ERROR. And when you have READ EVENTS, also somewhere users can cause CLEAR EVENTS. For example in the main.scx destroy or as a manu item for quitting the application.

Chriss
 
Thank you for the reply!

I already set it to main and it works but there's a window at the back of the form. How can I remove that so only the form will appear?

mailsys_a8sgwn.png
 
Mike Lewis already addressed this. This is the _screen. Which in VFP9 itself is the IDE main window.
You can hide it, but then you also hide your own form, as by default forms are child windows of _screen:

inscreen_odxhxp.png

To not have _screen visible, you first need to change this, so your form becomes a top level form, that is ShowWindow has to become 2.

And then you can hide the screen. The best way to do that is create a new text file with SCREEN=OFF, save it as config.fpw and include it in the project files. All that is what Mike Lewis talked about already.

But think twice about it. If your application grows, it's not unusual to have a main screen in which all your application forms become child windows. That screen is like your applications desktop and makes it simpler to move all your application windows into another display. In short it's what's called MDI application, multiple document interface. And way back VFP was new in Windows that also was the norm for applications, you still know a lot like that, MS Word, for example, also other Office applications.
img5_wmcijs.jpg

A VFP app looks a bit different, but the principle stays, you see this screen has the system menu, most items don't work as they are IDE features not available at runtime, but you can easily generate a menu you design starting from scratch or a standard menu and you can also have a docked toolbar. Besides there are helper projects like
But, well, I hear you, just the form right now. And after you have made your form to its own top level form and have that screen=off config.fpw, you'll only see your own form on the windows desktop when you start your exe.

Chriss
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top