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.

Set Talk On


Define Class ClickHandler As Session
  Procedure Build
   Build Exe webadmin.exe From webadmin Recompile

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.