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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How To Make a Single-Form-Application

Forms & Screen

How To Make a Single-Form-Application

by  Olaf Doschke  Posted    (Edited  )
There are some FAQs on READ EVENTS, some on how to turn off the _SCREEN, some how to suppress the creation of a FOXUSER.DBF and some on How to setup a form as top level form.

I think these questions are closely related and mostly come from new VFP users, that try to do something simple first, a single form application with no menu, no MDI (multiple dcument interface). But because VFP offers no project types and so you don't get a template project, you need to find out several things yourself, that seemed easy to do. In fact an MDI application is easier to setup with VFP. And one problem even only gets obvious, when first compiling and running the EXE, just to see a flicker because of a missing READ EVENTS.

Here are two programs (you can save as prg and run), that create and compile a single-form-application each. One program will create a project based on a form (SCX), one program will create a project based on a form class (VCX). There are some differences between SCX and VCX. I'd always recommend basing your project on classes. The tempting thing of an SCX is, you have the RUN Button and off you go, rapid development. But you cannot inherit form classes of SCX forms. In a single form application that does not matter much, but the chances are high, you want a second form soon, then a third...

Simply save one of these as a prg. If you want your project created in another path, simply change line 1. Then run, you'll get a very simple project with a top level form, a config.fpw, that turns off the vfp screen and suppresses creation of a FOXUSER.DBF and a main program (a concept quite similar to C: VFP projects have a main file - not function - , which is the entry point of the EXE). An EXE is built and run and no foxuser.dbf is created in the application/project folder, which may later save trouble, when installing into C:\Program Files\YourApp\, in which users don't have the right to create new files.

VCX:
Code:
#Define ccPropjectpath [D:\vfpprojects\singleformVCX\]
MkDir (ccPropjectpath)
Cd (ccPropjectpath)
MkDir [libs]
MkDir [others]
MkDir [prgs]

Create Project singleformVCX.pjx Nowait Save

Local lcFile
Text To lcFile Noshow
On Shutdown Quit
Set Classlib To [forms] Additive
Local loMainform
loMainform=Createobject("frmmain")
loMainform.Show()
Read Events
EndText
StrToFile(lcFile,"prgs\main.prg")
_vfp.ActiveProject.Files.Add("prgs\main.prg")

Text To lcFile Noshow
SCREEN=OFF
RESOURCE=OFF
ALLOWEXTERNAL=ON
EndText
StrToFile(lcFile,"others\config.fpw")
_vfp.ActiveProject.Files.Add("others\config.fpw")

Local Array laForm[1]
Local loForm
Create Class frmMain Of [libs\forms.vcx] As Form Nowait
ASelObj(laForm,1)
loForm = laForm[1]
loForm.ShowWindow = 2 && as top level form
loFOrm.Autocenter=.T.
loForm.Caption="Main Form"
loForm.WriteMethod("Unload","Clear Events")
Activate Window "Class Designer" && change in localized VFP versions
Keyboard '{CTRL+S}'
Keyboard '{CTRL+F4}'
Doevents
_vfp.ActiveProject.Files.Add("libs\forms.vcx")
_vfp.ActiveProject.Build("singleformVCX.exe",3,.t.,.t.,.t.)

SCX:
Code:
#Define ccPropjectpath [D:\vfpprojects\singleformSCX\]
MkDir (ccPropjectpath)
Cd (ccPropjectpath)

MkDir [forms]
MkDir [others]
MkDir [prgs]

Create Project singleformSCX.pjx Nowait Save

Local lcFile
Text To lcFile Noshow
On Shutdown Quit
Do Form frmMain
Read Events
EndText
StrToFile(lcFile,"prgs\main.prg")
_vfp.ActiveProject.Files.Add("prgs\main.prg")

Text To lcFile Noshow
SCREEN=OFF
RESOURCE=OFF
ALLOWEXTERNAL=ON
EndText
StrToFile(lcFile,"others\config.fpw")
_vfp.ActiveProject.Files.Add("others\config.fpw")

Local Array laForm[1]
Local loForm
Create Form [forms\frmMain.scx] As Form Nowait
ASelObj(laForm,1)
loForm = laForm[1]
loForm.ShowWindow = 2 && as top level form
loForm.Autocenter=.T.
loForm.Caption="Main Form"
loForm.WriteMethod("Unload","Clear Events")
Activate Window "Form Designer" && change in localized VFP versions
Keyboard '{CTRL+S}'
Keyboard '{CTRL+F4}'
Doevents
_vfp.ActiveProject.Files.Add("forms\frmMain.scx")
_vfp.ActiveProject.Build("singleformSCX.exe",3,.t.,.t.,.t.)

Bye, Olaf.
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top