A button to build a project

[Command button on the VFP desktop] Visual FoxPro is an object-oriented language and the development tool itself is object-oriented. The desktop is an object represented by the _screen keyword and has properties and methods in the same way as any other object. A simple use of these is to change the colour and font of the screen:

_screen.backcolor = RGB(0, 0, 0)
_screen.forecolor = RGB(0, 255, 0)
_screen.fontname = "Courier New"

This gives a retro green-on-black screen in typewriter font.

A more sophisticated technique is to treat the FoxPro desktop as a container and add objects to it at runtime. This example adds a command button to the the desktop as a useful shortcut during development work:

There are two stages to the job. The first is to add the command button to the desktop; the second is to bind its Click event to some useful code. In this case, it's the code that that will build the VFP executable from a project

Public oHandler

*-- We don't want to see progress reports as the
*-- button object is created.
Set Talk Off

*-- Bind the click event to a handler
oHandler = Newobject ("ClickHandler")

With _Screen
  .AddObject ('cmdBuild', 'commandbutton')
  Bindevent (_Screen.cmdBuild, "Click", oHandler, "Build")
  With .cmdBuild
   *-- Set the appearance of the button first ...
   .Caption = "Build"
   .Top = 10
   .Left = 10
   .Height = 27
   *-- ... then make it visible.
   .Visible = .T.
  Endwith
Endwith

Set Talk On

Return

*----------------------------------------
Define Class ClickHandler As Session
  Procedure Build
   Build Exe webadmin.exe From webadmin Recompile
  Return
Enddefine

The button saves the four or five mouse-clicks needed to build an executable from the VFP Project Manager. It might not save much time on a single build but the savings build up during the day.

Use the VFP startup technique described here to create this command button automatically as Visual FoxPro loads.

MS Access technical tips

Visual FoxPro technical tips

General Tips

 

More tips from Alvechurch Data

Alvechurch Data - Microsoft FoxPro and Access Database Development and Training

Alvechurch Data are based close to Birmingham and provide Microsoft Access and Visual FoxPro training, development and support.

Read More

Autocomplete in Visual Fox Pro

Autocomplete in Visual Fox Pro

The textbox class in Visual FoxPro 9 has a new Autocomplete property which shows the user the previous values that have been entered in that textbox.

Read More

FoxPro Functions

FoxPro has always had functions like FREAD and FWRITE to read and write files at a low level. They can handle files which defeat the STRTOFILE and FILETOSTR functions.

Read More

Development Services

Alvechurch Data specialise in Microsoft Access and Visual FoxPro databases and have fifteen years experience developing databases for small business use.

Read More

Access and Visual FoxPro Training

Microsoft Access and Visual FoxPro training courses and workshops offered by Alvechurch Data in Birmingham.

Read More