The Visual FoxPro Solutions samples are a collection of independent samples designed to illustrate particular features of Visual FoxPro. The Solutions samples also include examples based on the Visual FoxPro Foundation Classes.
To run the Solutions Sample application
Enter the following in the Command window:
DO (HOME(2) + 'solution\solution')
- From the Program menu, choose Do.
- Choose the \Samples\Solution folder.
- Double-click Solution.app.
From the main Solution Samples form, you will see that the samples are organized into the following categories: ActiveX controls, Visual FoxPro controls, Databases, Forms, FoundationClasses, Menus, Reports, Toolbars, and Windows API. To see all of the components in this tree view, choose the Expand All button and scroll through the components.
When you have found a sample or component that interests you, highlight it to select it. You can then do one or all of the following:
- Read a brief description of the sample in the description area at the bottom of the main Solutions form.
- Run the sample by choosing Run Sample.
- See the code by choosing See Code.
- Get Help on the sample you are running by pressing F1 or clicking the ? button.
After you close the form or designer that is opened, you are returned to the main Solutions form.
How the Solutions Samples Work
Each component of the Solutions sample is listed in Solution.dbf. This table stores the following:
- The key and parent key ids required to add nodes to a treeview control.
- The image id in the ImageList control for the picture to be displayed beside the item in the treeview control.
- The file name and path of the components.
- The method to open when you choose See Code.
- The description to be displayed in the Visual FoxPro Solutions form.
There are two additional tables used to provide filtered list access to the components: Xref.dbf and Reftext.dbf.
The FillTree method of the Solution.scx reads the information from Solution.dbf to fill the treeview control.
* FillTree o = THIS.pgf1.pagTree.oleTree SCAN IF ALLTRIM(parent) = '0' oNode = o.nodes.add(,1,ALLTRIM(key),ALLTRIM(text),,) ELSE oNode = o.nodes.add(ALLTRIM(parent),4,ALLTRIM(key), ALLTRIM(text),,) ENDIF * add images to the treeview IF !empty(image) oNode.Image = ALLTRIM(image) ENDIF ENDSCAN
The interface for Solutions.app is Solution.scx and provides several features:
- Two ways to view the contents: As a tree (outline) view, which shows the hierarchy of the components in the application, or as a filtered list view of the components in the application, which provides an alphabetical list of all components that will filter the list according to your sort specifications.
- An expand/collapse button for viewing all of the components in the tree view.
- A brief description of a selected sample.
- The option to run the code and/or view the code by opening it in the appropriate designer.
A description of how specific features were implemented on any form can be seen using the Behind the Scenes button.
Each form in the Solutions suite contains an object based on the c_solutions class in Solution.vcx. This class provides a single place for environment and localization settings. When the c_solutions object is destroyed, old settings are restored and, if the Solutions form exists, it is redisplayed.
The custom class is used in the Solutions sample because it provides greater flexibility: you can add it to existing forms, and, if you want, you can delete it from the forms in the Solutions suite and customize the forms for your own use. Instead of using a custom class to manage the environment settings, you can provide this functionality in one form class from which all forms in the Solutions sample are derived.
Form records in Solution.dbf have a value of "F" stored to the type field. In the code associated with cmdRun and cmdSee, the form is run or modified.
* extract from cmdRun.Click CASE solutions.type = "F" && form DO FORM (ALLTRIM(solutions.path) + "\" + ALLTRIM(solutions.file))
Note In the Data Environment of Solution.scx, the cursor for Solution.dbf is given an alias of "Solutions."
Reports and Queries
Report records in Solution.dbf have a value of "R" stored to the type field, and queries have a type of "Q". You can run the reports and queries in the code associated with cmdRun, and you can modify them in the code associated with cmdSee.
* extract from cmdRun CASE solutions.type = "R" && report REPORT FORM (ALLTRIM(solutions.path) + "\" + ALLTRIM(solutions.file)) PREVIEW NOCONSOLE THISFORM.Visible = .T.
Running a query opens the result set in a Browse window. By default, a Browse is displayed in the currently active window, which in this sample would be the Solutions form. To display the Browse in a separate window, this code defines and activates another window, runs the query, and then releases the separate window.
CASE solutions.type = "Q" && query #DEFINE TITLE_LOC "Results of query " DEFINE WINDOW brow_wind FROM 1,1 TO 30, 100 TITLE TITLE_LOC + UPPER(ALLTRIM(file))+ ".QPR " ; FLOAT GROW MINIMIZE ZOOM CLOSE FONT "Arial",10 ACTIVATE WINDOW brow_wind NOSHOW DO (ALLTRIM(solutions.path) + "\" + ALLTRIM(solutions.file) + ".QPR") RELEASE WINDOW brow_wind THISFORM.Visible = .T. ENDCASE