Sample Class Libraries
The Visual FoxPro sample class library provides encapsulated functionality that you can easily add to your applications. The Solution Samples illustrate using most of the sample classes. The sample classes are contained in the following files:
Buttons Class Library
Samples Class Library
Utility Class Library
Registry Program
Buttons Class Library
Buttons.vcx contains the following classes.
Class |
Description |
---|---|
CmdOK |
A command button that releases the form it is added to. If the form is contained in a form set, cmdOK releases the form set. |
CmdCancel |
A subclass of cmdOK with the Caption property set to "Cancel." |
CmdHelp |
A command button that invokes Help with the HelpContextID of the form to which it is added. |
MailBtn |
A container with a command button, a Microsoft MAPI Message control, and a Microsoft MAPI Session control. Code in the Click event of the command button logs on to mail and composes a message containing the values in the current record of a table. For an example of using the MailBtn class, see SENDMAIL.SCX in the Visual FoxPro Samples\Solution\OLE folder. |
VCR |
A set of table navigation buttons that makes it possible for a user to move the record pointer to the next, prior, top, and bottom records of a table. Set the Skiptable property to the alias of the table you want to move the record pointer in. If Skiptable is empty, the record pointer is moved in the currently selected work area. |
Samples Class Library
Samples.vcx contains the following classes.
Class |
Description |
---|---|
CboFontName |
A combo box that displays all the currently available fonts in the system. |
CboFontSize |
A combo box that displays all the available point sizes for a particular font. Pass a font name to the FillList method to populate the combo box. The nLargestFont and nSmallestFont properties delimit the maximum and minimum font sizes displayed. You can use this control in conjuction with the cboFontName class. In the InteractiveChange event of the cboFontName object, call the FillList method of the cboFontSize object: THISFORM.cboFontSize1.FillList(THIS.Value) For an example of using this class, see the tbrEditing class in the same class library. |
Clock |
A container that displays the current date and time. The "Display a system clock" component in the Solutions sample also uses the Clock class. |
Datachecker |
A custom class that manages resolving data conflicts. Code in the Error event of the VCR class in BUTTONS.vcx calls the CheckConflicts method of this class if an attempt to write buffered data to a table encounters changed values: nConflictStatus = ; THIS.DataChecker1.CheckConflicts() The "Run multiple instances of a form" component in the Solutions sample also uses this class to check for data conflicts. For more information, open the class and read the comments in the code. |
Distinct_values_combo |
A combo box that is populated on initialization with the distinct values in the ControlSource alias. For example, if you add this class to a form and set the ControlSource to "customer.country", the combo box will be populated with the countries in the customer table without displaying the country names more than once. |
FrmNoTitle |
A form with properties set so that no title is displayed. If you want to display information in a separate window, you can create an object based on this class and use form graphics methods. The "Display line animation on a form" component in the Solutions sample also uses a form with no title to display the animation. |
Lookup_combo |
A combo box that makes it easy to display values from one field, for example a company name, while binding a ControlSource to another field, for example a company id number. This class has four custom properties: order_column: Column to sort the table by (optional). lookup_table: Table to fill the combo box from. display_column: Column in the table to display. return_column: Column whose value is written to the ControlSource. |
MoverLists |
A container with two list boxes and four command buttons. A user can move selected items from one list to the other list by clicking the command buttons or by dragging and dropping. You need to make sure the RowSourceType of each list box is set to 0 and use the AddItem method to add items to the source list box. MoverLists has three custom properties: CanDropIcon: Cursor to be displayed over a valid target in a drag and drop operation. NoDropIcon: Cursor to be displayed when dropping will not add the selected items to the list box. DragThreshold: Number of pixels before the drag operation begins. The "Move items between list boxes" component in the Solutions sample illustrates the use of this class. |
Print_reports |
A modal form that makes it possible for a user to preview a report, print it, or direct it to a file. You can set the cReport property of the class to the name of the report or pass the report name in as a parameter: o = CREATEOBJECT(print_reports, ; "myreport.frx") |
QBF |
A container with three command buttons. Add this class and the VCR class to a form with data-bound controls. When the user chooses Enter QBF, the values in the controls are blanked out. Values that the user enters in the controls specify the filter to be set on the table when the user chooses Query. The controls need to have a ControlSource set and the Parent of the controls needs to be the form, not another container. The "Create a query by example form" component in the Solutions sample illustrates the use of this class. |
Resizable |
A custom class that manages resizing and repositioning the controls on a form at run time, maintaining their relative sizes and positions. Add the class to a form and, in the Resize event of the form, call the AdjustControls method: THIS.Resizable2.AdjustControls Resizable has two custom properties you need to set: RepositionList: A string containing all the classes for which objects are repositioned. ResizeList: A string containing all the classes for which objects are resized. The "Resize and reposition controls at run time" component in the Solutions sample illustrates the use of this class. |
RTFcontrols |
A container class containing cboFontName, cboFontSize and command buttons for Bold, Italic, and ForeColor. The cboFontSize control is refreshed in the InteractiveChange event of cboFontName, but no additional functionality is coded with the Bold, Italic and ForeColor command buttons. The "Use the RichText control" component in the Solutions sample illustrates the use of this class. |
SoundPlayer |
This class can be used to play a non-visual multimedia file such as a .WAV audio file. See the following section, Sample Multimedia Classes, for more information about this class. |
StopWatch |
A container class with a timer and labels to display stop watch values. StopWatch has three custom methods you'll want to use: Start: Starts the stop watch Stop: Stops the stop watch Reset: Resets the displayed time to 0:00 The "Display a stop watch" component in the Solutions sample illustrates the use of this class. |
TbrEditing |
tbrEditing has a custom property and a method you'll want to use: nAppliesTo Property: This property can be set to 1, 2, or 3.
Refresh: Accepts an object reference as a parameter and sets all the editing controls to the appropriate values of the object. Call the Refresh method in the GotFocus event of a control. The "Change font attributes" component in the Solutions sample illustrates the use of this class. |
VideoFrame |
This class can be used to play a visual multimedia file, such as a video for Windows file. See the following section, Sample Multimedia Classes, for more information about this class. |
Sample Multimedia Classes
Two of the classes (SoundPlayer and VideoFrame) in the Visual FoxPro Samples\Classes\Samples.vcx class library make it possible for you to use the MCI (Multimedia Command Interface) to play multimedia files.
To locate documentation for the MCI commands, search for "Multimedia Commands" in the MSDN Library (https://msdn.microsoft.com/library).
Sound Player Class
This class can be used to play a non-visual multimedia file, such as a .WAV audio file. It makes it possible for you to specify the file to be played, and then provides built-in methods to easily play the media file.
Property |
Description |
---|---|
AutoOpen |
Specifies whether the sound file should be automatically opened and displayed when the object is instantiated. The default value is True (.T.). |
AutoPlay |
Specifies whether the sound file should be automatically played when it is opened. The default value is True (.T.). |
AutoRepeat |
Specifies whether the sound file plays continuously. The default value is False (.F.). |
ControlSource |
Specifies the column that contains the sound file reference. If empty, the class expects a static file name to be in the SoundFile property. |
MCIAlias |
Specifies the alias to be used by MCI. If left empty, the alias defaults to the Name property of the class. Normally this can be left empty, but if the user wants to play the same sound file twice at the same time, a different alias would need to be specified for each. |
SoundFile |
Holds the name of a sound file to play, for example "C:\WINDOWS\CHIMES.WAV". |
Method |
Description |
---|---|
OpenSound |
Opens the sound file. |
PlaySound |
Plays the sound file. The file must be opened with the OpenSound method before it can be played. |
PauseSound |
Pauses the playing of a sound file. Play can be continued by calling the PlaySound method. |
SetPosition |
Makes it possible for the user to specify the position of the media file. It can be executed at any time after the file has been opened. Valid values are "Start," "End," or a specific millisecond into the sound. |
CloseSound |
Closes the sound file and releases all resources associated with it. |
VideoFrame Class
The VideoFrame class can be used to play a visual multimedia file such as a video for Windows file. This class makes it possible for you to position and size the video to be played, and then provides built-in methods to easily play the media file.
For an example of using this class, see Video.scx in the Visual FoxPro Samples\Solution\Forms folder.
Property |
Description |
---|---|
AutoOpen |
Specifies whether the video file should automatically be opened and displayed when the object is instantiated. The default value is True (.T.). |
AutoPlay |
Specifies whether the video file should automatically play when it is opened. The default value is True (.T.). |
AutoRepeat |
Specifies whether the video file will loop the video. Setting this to .T. will cause the video to play continuously. The default value is False (.F.). |
ControlSource |
Specifies a Field that contains the video file reference. If empty, the class expects a static file name to be in the VideoFile property. |
MCIalias |
Specifies the alias to be used by MCI. If left empty, the alias defaults to the Name property of the class. Normally this can be left empty, but if the user wants to play the same video file twice at the same time, a different alias would need to be specified for each. |
VideoFile |
Holds the name of a video file to play, for example: "C:\VFP\SAMPLES\SOLUTION\FORMS\FOX.AVI". |
Method |
Description |
---|---|
CloseVideo |
Closes the video file and releases all resources associated with it. |
DoMCI |
Called by the other methods to execute MCI commands. It can also be called by a user to execute a specific MCI command. |
OpenVideo |
Opens the video file and shows the first frame. |
PauseVideo |
Pauses a playing video. The video can be restarted by using the PlayVideo method. |
PlayVideo |
Plays the video file. The video file must be opened in the OpenVideo method before it can be played. |
SetPosition |
Makes it possible for the user to specify the position of the media file. It can be executed at any time after the video file has been opened. Valid values are "Start", "End", or a specific millisecond into the video. |
Utility Class Library
Utility.vcx contains the following classes.
Class |
Description |
---|---|
Arraylib |
A custom class with methods for inserting array elements, deleting array elements, and scanning array columns. |
Execsp |
A custom class with methods that facilitate SQL pass through and executing stored procedures on a remote database. |
Filelib |
A custom class with methods that perform common string tasks used when manipulating file names, for example, removing the extension, adding a backslash to a path, and so on. |
Menulib |
A container class with methods that create a shortcut menu from an array. The "Create dynamic shortcut menus" component in the Solutions sample illustrates the use of this class. |
Registry Program
Registry.prg contains the following classes.
Class |
Description |
---|---|
FileReg |
A subclass of the Registry class that provides methods for reading the application associated with particular file extensions and the path to the application. |
FoxReg |
A subclass of the Registry class that provides methods for reading and writing Visual FoxPro settings in the Windows Registry. |
ODBCReg |
A subclass of the Registry class that provides methods for reading ODBC data source and driver information. |
OldINIReg |
A subclass of the Registry class that provides methods for reading and writing to an .INI file. |
Registry |
A custom class that provides methods for accessing Windows API functions for manipulating the Windows Registry. |
For examples of using the registry classes, run SOLUTION.app in the ..\Samples\Solution folder.