Return to the first section of the Evaluator's Guide.
With Visual FoxPro version 5.0, a developer or a team of developers can experience productivity improvements and leverage current mastery of the other tools in the Microsoft family of Visual Tools, including Visual Basic, Visual C++, and Microsoft Access. Enhancements include:
- Integration with Microsoft Visual SourceSafe for project-oriented team development
- Improved color-coded debugging and editing facilities
- Addition of a multi-user database container and multi-developer project manager tools
- Support for outer joins, and other rapid application development improvements
Visual SourceSafe Integration
Visual FoxPro version 5.0 provides total integration with the Microsoft Visual SourceSafe project-oriented team development system. Development teams and individual users can coordinate their efforts, avoid expensive coordination errors, and extend control over the versioning process. Visual SourceSafe, which is purchased separately from Visual FoxPro, provides code module check-in and check-out, views that show the differences between versions, a view of a files history, and so forth. Visual SourceSafe functionality is available from within the Visual FoxPro menu system, so developers dont leave the development environment to manage the project, resulting in more time spent developing and less time spent managing.
Figure 5 shows the Project Manager from a project under Visual SourceSafe source code control, along with the Project menu.
Enhanced Editing and Debugging
The editor in Visual FoxPro version 5.0 provides functions that convert, block indent, and comment an entire line or block of code when a developer chooses a command in the shortcut menu. Color-code lines of program code can also be chosen automatically and the colors configured to the developers preferences. This makes it easier for each developer to write, navigate, and read Visual FoxPro code.
Prior to version 5.0, developers used the Trace and Debug windows to debug FoxPro applications. Now, Visual FoxPro includes a full-featured debugger that runs in its own separate window. The debugger includes advanced features, such as the ability to save and load a debugging session, persistence of settings between sessions, event tracking, coverage logging, and complex breakpoint support. Drag and drop is fully enabled among all debugging surfaces.
Multi-user Database Container
In response to customer requests, the Database Container, which is the main design surface for the database schema, is now multi-user. Developers can now collaborate on schema design.
You can review Opening the Database Container for shared access by choosing Figure 6.
Note The Project Manager window uses Visual SourceSafe to support multiple developers.
Other Rapid Application Development Features
Two additional rapid application development (RAD) features not discussed earlier are the increased power a developer has over control placement on forms and Query Designers support of outer joins.
When adding a control to a form, a developer can configure its default behavior. Field controls added to forms are instantiated with captions and their field name by default, and include an appropriate control based on the field type. For example, a memo field creates a scrolling edit region by default.
In Figure 7, you can see a field named discount in the Customer table. This field has been configured to default to a spin box when placed on a form and to use a more descriptive caption than a simple field name.
Now, whenever a developer adds the field to a form, it will automatically use a spin box captioned Normal Discount.
A developer can use the Display Library setting, where a class library can be associated with a data type. This way, a developer can create a set of pre-configured, customized controls for all or certain data types in their system. This decreases development time and increases consistency within applications.
Outer joins, which previously required that a developer hand-edit SQL code, are now fully supported in the version 5.0 Query Designer. This means faster construction and reduced debugging time for outer join queries.
You can review how outer joins are supported in Query Designer by choosing Figure 8.
By focusing on ActiveX extensibility and interoperability, increased performance, improved connectivity, and the enhanced development environment (each detailed above) the Microsoft Visual FoxPro version 5.0 team has built a product that continues the Visual FoxPro leadership tradition while supporting developers who build state-of-the-art Internet and client/server database solutions.
You can acquire Visual FoxPro on this Web site when you click the Shop button at the top of this guide. If you are new to acquiring software on the World Wide Web, you can read Before You Shop .
Also, you can read more about Visual FoxPro on the Web site at www.microsoft.com/vfoxpro/ .
Finally, you can see some of the new features of Visual FoxPro version 5.0 in action by taking the following Test Drive.
The purpose of this test drive is to highlight a few features of Visual FoxPro version 5.0. The best way to understand it is to use the product. If you dont own these products, you can follow the procedures and review the graphics that show the results of these procedures.
Required Software
In order to complete the test drive, youll need:
- Microsoft Windows® 95 or Windows NT Workstation 4.0
- Microsoft Visual FoxPro version 5.0
Setup Instructions
Before using the step-by-step instructions, install Microsoft Windows 95 and Microsoft Visual FoxPro version 5.0.
Open Visual FoxPro Version 5.0
- To open the program, double-click the Visual FoxPro version 5.0 icon.
- From the startup options, choose Create a New Project, name it Test, and then choose Save.
When you complete these steps, your screen should look like Figure 9.
Command Window
You may see a Command window appear along with the new project you just created. The Command window is a Visual FoxPro version 5.0 system window you can use to type FoxPro commands and functions. While most tasks can be performed using the Visual FoxPro graphical interface, the Command window is a convenient mechanism for executing commands in rapid succession.
Project Manager
You can use the Project Manager to organize and manage your files in projects. When the Project Manager window is active, Visual FoxPro displays the Project menu on the menu bar. The Project Manager consists of tabs that sort Visual FoxPro files into groups, such as databases, forms, reports, labels, menus, and programs.
Using the Project Manager, you can tear-off individual tabs. Treat it as you treat a dockable toolbar. You can use an individual tab to drill down into specific components to review more details.
Add a Database
- In Project Manager, choose the Data tab.
- Click Databases in the hierarchy, and choose Add.
- In the Open File dialog box, choose Samples, then Data, then Testdata.dbc.
- Click Open.
You can explore the contents of the TESTDATA database by clicking on the (+) symbols. You can see the results of drilling down to the tables in Figure 10.
View the Database Table
You can use the Project Manager to view data.
- Select the Customer table from the list.
Note Additional buttons are enabled.
Note You can view data from the Customer table in the spreadsheet-like window. Navigate through this table field by field or record by record.
- Close the Browse window when you are finished.
Using the Form Designer for Simple Forms
Using the Visual FoxPro Forms Designer, you can create complex forms involving one-to-many relationships, and you can add ActiveX Controls to forms. Also, you can subclass these controls using the object-oriented architecture of Visual FoxPro.
Open a New Form
- With the Project Manager still open, on the toolbar or from File, choose New. Select Form, and then choose New File.
When you view the Form Designer, your screen should look like Figure 11.
Note You may need to rearrange some windows to view everything.
You can use the Form Controls toolbar to add any type of control, including ActiveX Controls. Set properties for the form or for a selected control on the form using the Property Sheet. Explore any property by highlighting a property, right-clicking the Property Sheet title bar, and choosing Property Description from the shortcut menu.
Change Properties
- Click the Caption property, and in the textbox, type
Employees
Note The form title changed to reflect your typing.
- Click the BackColor property, open the Color dialog box (click Command, the key with ellipsis), and choose a color from the color picker.
- When you are finished, close the Controls toolbar and the Property Sheet.
Add a Control
Add controls to your form by using the drag-and-drop technique. You can use the smart field-mapping engine or your own user-defined class to map a control to a data type.
- In Project Manager, choose the Data tab, and then select the Testdata database.
- Choose the Employee table in the database, and drill down to the field level.
- Use the drag-and-drop technique to add first_name.
Note Visual FoxPro added a caption for the name of the field automatically.
When you complete these steps, your screen should look similar to Figure 12.
Add More Controls
Use the Notes control, a memo data type control, so a user can type large amounts of text. The Photo control is a general data type you can add so a user can store an OLE object, such as an image.
- Using the same technique you used to add first_name, add the last_name, emp_ID, notes, and photo controls to the form.
Save and Run the Form
- To run the form, click Run (button with exclamation point) on the Standard toolbar.
- When prompted to save the form, type
emp1
and then choose Save.
When you complete these steps, your screen should look like Figure 13.
Toggle between design mode and run mode by clicking a button on the Standard toolbar. To choose design mode, click Modify Form (button with triangle, ruler, and pencil).
Resize a Control
- Click Modify Form to return to the Form Designer.
- Click and drag the controls you want to resize.
This form can display only a single record. Using a predefined class, you can add a set of navigation buttons to move through the table and view other employee records.
Add Navigation to a Form
- In design mode, select the form.
- To display the Form Controls toolbar, from View, choose Form Controls.
- From the Form Controls toolbar, click Class Library (button with books), which opens the Add submenu you need.
You can review a Form Controls toolbar showing Class Library button activating Add submenu by choosing Figure 14.
- From the Open File dialog box, choose Samples, Classes, and then Buttons.vcx class library file.
Your toolbar will dynamically change to display buttons as shown in Figure 15.
Note You can return the toolbar to the Visual FoxPro base classes by choosing Standard from the Class Library button.
- To add the VCR navigation buttons to the form, click the first vcr button, and then click the form.
Note To run the form and test the navigation, click Run on the Standard toolbar.
When you add the VCR navigation buttons, your form should look like Figure 16.
Use the Form Data Environment
We want to see the employee information as above, together with corresponding orders relating to each employee. In a previous step, you used the Project Manager and the drag-and-drop technique to add controls on the form. This time, we will use the Visual FoxPro Form Data Environment. The Data Environment stores data sources used by a specific form. Well use the drag-and-drop technique to add the orders table to the customer form, creating a one-to-many form.
Make the Form a One-to-Many Form
- In design mode, right-click a blank area on the form, and choose Data Environment from the shortcut menu.
Note When the Data Environment window is displayed, it will contain the Employee table. It was added automatically when you first dragged the control to the form from this table using the Project Manager.
- Right-click the Data Environment window and choose Add from the shortcut menu. When prompted for a table, choose the Orders table.
When you complete this step, your screen should look like Figure 17.
Notice the line attaching the two tables. This line represents a relationship between the two. Using this relationship, you can create one-to-many forms that are synchronized on a key field that relates them.
- Select the Notes and Photo controls and their captions, and delete them from the form.
- Click in the Data Environment window; using the table's title bar, drag the Orders table to the form.
- Click Run on the Standard toolbar to run the form.
Note As you navigate through the records, the one-to-many relationship between Employee and Orders is maintained.
As you navigate through the database, your screen should look like Figure 18.
Add an ActiveX Control to the Form
You can add ActiveX Controls to your form using Visual FoxPro version 5.0. You can use any of the 26 controls included with Visual FoxPro. You can use the Visual FoxPro object-oriented support to sub-class ActiveX Controls or to add or modify functionality in your applications.
- Close all the open windows so you can start fresh.
- Open a new form. From the Form Controls toolbar, click OLE Container Control, and then click on the upper left corner of the form.
- In the Insert Object dialog box, choose Insert Control.
- After the list refreshes, from the Control Type list, choose the Calendar Control.
Set ActiveX Properties
You can set properties using the Property Sheet. With ActiveX Controls, however, use either the Visual FoxPro Property Sheet or a Property Sheet specific to the control.
- Right-click the ActiveX Control and choose Calendar Control Properties from the shortcut menu.
- Choose the Colors tab, and pick a color.
- When you've finished setting and changing properties, click Run on the Standard toolbar.
- When prompted, save your form as CAL1.
When you finish with these steps, your screen should look like Figure 19.
Create an ActiveX Control Subclass
As mentioned above, you can use Visual FoxPro to subclass ActiveX Controls. Unlike forms that are stored in .SCX files, classes are stored in class libraries with a .VCX file extension. In this step, we'll add code that executes when a user clicks a day in the calendar.
- In design mode, click Calendar. (If necessary, click Modify Form on the Standard toolbar.)
- If necessary, from View, choose Property Sheet.
Note If you see Olecontrol1 in the dropdown, the control is selected. If not, click the control.
- On either the All or Methods tab, double-click Click Event.
- In the code snippet editor, type
*** OLE Control Event ***
MESSAGEBOX("Date: "+ALLTRIP(STR(this.month))+"/"+;
alltrim(STR(this.day))+"/"+:
alltrim(STR(this.year)))
You can look at the snippet editor containing this code in Figure 20.
Test Your Code
- Close the snippet editor and choose Run from the Standard toolbar.
Note Because you added the code correctly, youll see a message dialog box that contains the date you clicked.
Save As a Class
In design mode (if necessary, click Modify Form, on the Standard toolbar), click the Calendar control to select it. In this step, youll create a class library named CAL1.VCX.
- From File, choose Save As Class.
- In the Save As Class dialog box, type CAL1 in the Name and File boxes, and then choose OK.
- Close the form.
You can see the Save As Class dialog box in
Figure 21.
Use the Class in a New Form
- From File, choose New. In the New File dialog box, choose Form.
- In the Form Designer, click Class Library on the Controls toolbar.
- From the menu, choose Add. From the Add dialog box, choose CAL1.VCX.
Note The toolbar buttons dynamically update to conform to the CAL1 Class.
- Choose CAL1 Class and drop it on the new form.
Save the New Form
- From File, choose Save.
- In the Save As dialog box, name this form CAL2.
- Click Run on the Standard toolbar to run the new form.
Note All the class attributes saved as CAL1 were inherited, such as the color and the click event logic.
Change the ActiveX Control Color
- From File, choose Open.
- From the dropdown, choose Visual Class Library, and then choose the CAL1.VCX class.
- In the new dialog box, choose Open.
You are now in the Class Designer with the Calendar Control open. The Class Designer is similar to the Form Designer, except you can use it to edit a class based on any control, including an ActiveX Control.
- Right-click the Calendar control to open the Calendar Control Properties dialog box.
- Change the color to yellow.
- Save and close the class.
View the Class Properties
- From Program, choose Do to rerun the CAL2 form.
- Change the File Type dropdown to Forms, and choose CAL2.SCX.
Note Changes made to the class when you changed CAL1.VCX are automatically reflected in CAL2 because they were inherited.
Visual FoxPro Debugger
Use the editor in Visual FoxPro to block indent and comment your code. You may have already noticed in the Command window that color-style syntax checking has also been added. Change the colors in the Options dialog box, which you can open from the Tools menu when you choose Options, and then choose Syntax Coloring.
You can review this dialog box in
Figure 22.
Prior to Visual FoxPro version 5.0, a developer used the Trace window and Debug window to debug FoxPro applications. Visual FoxPro includes a full-featured debugger that a developer will find to be one of the best available. The debugger runs in its own separate window and uses five window panes named Trace, Watch, Locals, Call Stack, and Output. The debugger includes event tracking, value tips, coverage logging, and complex breakpoint support. Drag and drop is fully enabled among all debug surfaces.
Set Up the Sample to Use the Debugger
To demonstrate the debugger, you can use a sample in the Solutions collection that ships with Visual FoxPro version 5.0. The Solutions collection contains more than 100 useful examples and ideas for forms, controls, menus, reports, and so forth.
You can view the Solutions display in Figure 23.
- From Help, choose Sample Applications.
- In Sample Applications, click Run next to the Solutions Sample topic.
- From the Controls/Listbox tab, choose Display Pictures in a List.
- Click Run Sample.
- Click Browse and find Samples, then Data. Choose Testdata.dbc.
When you choose Display Pictures in a List, your screen should look like Figure 24.
Open the Debugger
- From Tools, choose Debugger.
- From Windows, choose Watch.
- In the Expression dialog box, type
Application.ActiveForm
Use the Watch Window
In the Watch window, you can view updates with this object. You can change some properties using the Watch window. What you see in the window are all the properties of the form you are building in the currently running instance of Visual FoxPro.
- Click the plus sign (+) next to application.activeform.
- Change the forms caption by typing
View database contents
- Click the Value column for the Caption property, and notice the color change to red, which indicates the value has changed.
Note If you return to Visual FoxPro, you will see the new title bar caption.
When working in the Watch window, your screen should look like
Figure 25.
Set Breakpoints
Following these steps, youll set a breakpoint whenever a buttons click event is triggered.
- Return to the debugger, and close the Watch window.
- From Tools, choose Breakpoints.
- In the Location textbox, type
Click Click Add, then click OK.
In this step, notice the color-coded syntax, now used in all Visual FoxPro editing surfaces.
- Return to Visual FoxPro and click Browse.
Note The debugger appears with the Trace window opened to the Click event for that button.
- Press F8 to trace line by line through your code. To resume program execution, press F5. Stop when you pass
cRViewBMP = "dbrview.bmp"
- Position the pointer on cRViewBMP.
Note This is a memory variable; its value is displayed in a Value Tip.
- When prompted for a file, choose Cancel.
- Return to the debugger and open the Breakpoints dialog box, and then click Clear All.
- Close the dialog box.
When the Value Tip is displayed, your screen should look like
Figure 26.
Close the debugger, return to Visual FoxPro, and close both the current and the Solutions form.
Application Wizard
An addition to the development aids named Wizards and Builders is the new Application Wizard in Visual FoxPro version 5.0. Using the Application Wizard, you can create an entire application by binding forms, reports, and menus into one neat, ready-to-run package.
You can also use the Application Wizards predefined templates to create standard applications such as a Book, a Contact Manager, a Donation, or a Recipe database. The open architecture of the Application Wizard supports writing an original template or modifying an existing one.
One advantage of using the Application Wizard is it handles all the messy work of tying forms, reports, and labels together with menus. The Application Wizard uses a set of classes, which you can find in the Wizards directory, to perform the application-specific handling tasks. You can also modify these classes.
Start the Application Wizard
- From File, choose New, and then click Wizard.
- In the Application Wizard, in the Project Name textbox, type
Contacts
Note The updates in the Project File textbox show where the new application will be created. Override this smart path if you want.
When you open the Application Wizard, your screen should look like Figure 27.
Create a Project for Contacts
- From the opening Application Wizard page, choose Next to start Step 2.
- Click New Database from Template.
- From the dropdown, choose the Contacts template.
- Choose Finish.
- From the message box, choose Save Application and Run It, and then choose Finish.
Note This begins generating a project for your Contacts application.
At the completion of processing, youll see the application running with a new menu.
- From the Forms menu, choose Contacts.
When you choose Contacts, your screen should look like Figure 28.
Extra Driving
End this part of the test drive by choosing Exit from the File menu. Continue the Test Drive with Create Custom ActiveX Automation servers. If you want to drive farther, please continue with the following steps.
You can change the look of the forms, such as CALLS.SCX. When modifications are complete, you can rebuild and run the form.
Build and Run the Form
- Click Build. From the Build Options dialog box, choose the Build Application action.
- In Options, check Run After Build, and then click OK.
- When prompted for a file name, type CONTACTS.APP and replace the existing file.
The Build Options dialog box looks like
Figure 29.
Create Custom ActiveX Automation Servers
Use Visual FoxPro version 5.0 to create Automation servers (formerly known as OLE servers). Automation servers can be created and accessed by any application that supports Automation as a client, such as Visual Basic, Visual FoxPro version 3.0, Microsoft Excel, Microsoft Access, and so forth. Automation servers can be used in a variety of ways, such as business objects for three-tier architecture or Internet server-side components for Web-enabled applications.
In this example, we will create a custom server that retrieves FoxPro data and posts it to the Clipboard so applications such as Microsoft Word or Microsoft Excel can easily retrieve it.
- To begin anew, from File, choose New. Name your project FOXTEST.
- In the window, choose the Documents tab. Select Forms in the list box, and then choose New.
Note Do not pick the Wizard option in the subsequent dialog box.
- Open the Property Sheet and change to 2-As Top-Level Form. Change to Retrieve FoxPro Data.
Add Code
You can add code to handle the form being used to process data.
- In the Property Sheet, double-click Activate Event to open the Code Snippet Editor, then type
READ EVENTS
- Click the Procedure dropdown, select QueryUnload, then type
IF !EMPTY(ALIAS())
Application.DataToClip(,,3)
ENDIF
CLEAR EVENTS
Add Controls
- From the Controls toolbar, choose the Grid control and drop it onto the form.
- Resize the grid to work with it.
- From the Controls toolbar, choose the CommandButton control, add it to the form below the Grid, and then click CommandButton.
- From the Property Sheet, set the Caption property to
Get Data
When you add these controls to your form, your screen should look like Figure 30.
- Double-click the CommandButton to open the Code Snippet Editor window. Find the Click event in the Procedure dropdown. In this text window, type
cData = GETFILE("DBF")
IF !EMPTY(m.cData)
USE (m.cData) AGAIN SHARED
thisform.grid1.recordsource = ALIAS()
ENDIF
- Close the Code Snippet Editor.
- Close and save the form as FOXDATA.SCX.
Optional Testing
You can run this form to test your code. When you click the forms button, you are prompted to select any Visual FoxPro table. Choose one from the Samples subdirectory, then from the Data subdirectory. If all went well, the tables contents will appear in the grid. When you close the form, the contents of the table are transferred to the Clipboard. Test this by choosing Paste from the Edit menu in Microsoft Excel.
Create a Class As Entry Point for the Automation Server
- Choose the Classes tab, and then click New.
- Type
Class Name: foxdata
Based On: Custom
Store In: foxdata.vcx
- Click OK.
- From the Class Designer, choose New Method from the Class menu.
- Type
GetData
- Click Add, and then click Close.
When you open the New Property dialog box, your screen should look like
Figure 31.
- Open the Property Sheet and choose the Methods tab.
- Scroll to the bottom and double-click GetData to open the Code Snippet Editor.
- Type
DO FORM foxdata
- Close the window.
In this step, youll instruct Visual FoxPro to create and register this class as a Custom ActiveX Automation server.
- In Class Designer, from the Class menu, choose Class Info.
- In the Class Info dialog box, check OLE Public, and then click OK.
- Close the Class Designer.
Build the Server
The only window you should still have open is the Project Manager (FOXTEST). If not, close the others.
- On the Standard toolbar, click Build.
- In the Build dialog box, choose the Build Executable option, and then click OK.
Call your new Custom ActiveX Automation server FoxTest.FoxData from any application that supports being an ActiveX Automation controller. For example, use this Visual Basic, Applications Edition (VBA) version 5.0 code in Microsoft Excel to call this server:
Sub GetFoxData()
On Error GoTo myErrorCheck
Dim HadError As Boolean
HadError = False
Dim fox1 As Object
Set fox1 = CreateObject("foxtest.foxdata")
If HadError = False Then
fox1.getdata
ActiveSheet.Paste destination:=Worksheets("Sheet1").Range("A1")
End If
Exit Sub
myErrorCheck:
HadError = True
Resume Next
End Sub
The key lines of code instantiate foxtest.foxdata, and then take care of the paste (the line which begins ActiveSheet.Paste destination:=). This technique uses all the data access prowess of Visual FoxPro version 5.0, but makes the results available to virtually any application. The data access routine is encapsulated in the Visual FoxPro application, so any changes to the data access methods are localized to just a single Visual FoxPro program rather than to all the clients that potentially use this business object.
Congratulations! You have now completed the Visual FoxPro version 5.0 Test Drive.
You can acquire Visual FoxPro on this Web site when you click the Shop button at the top of this guide. If you are new to acquiring software on the World Wide Web, you can read Before You Shop .
Also, you can read more about Visual FoxPro on the Web site at www.microsoft.com/vfoxpro/ .
|
|