Data bound to objects on the form.
●
Top-level or child forms.
●
Multiple forms that can be manipulated together.
●
Forms based on your own custom templates.
●
Forms and form sets are objects with their own properties, events, and methods that you can set in the Form Designer. A form set consists of one or more forms that can be manipulated as a unit. If you have four forms in your form set, for example, you can display or hide them as a unit with a single command at run time.
Creating a New Form
You can create new forms in the Form Designer, and you can see how each object will appear to the user as you design it.
To create a new form
In the Project Manager, select Forms and choose New.
-or-From the File menu, choose New, select Form, and choose New File.
-or-●
Use the CREATE FORM command.
●
The Form Designer with toolbars: Form Designer, Controls, Layout, and Palette
For a more detailed description of the Form Designer, see Chapter 8, Managing Data Through Forms, in the User’s Guide.
Setting the Data Environment
Each form or set of forms includes a data environment. The data environment is an object that includes the tables or views the form interacts with and the relationships between tables that the form expects. You can visually design the data environment in the Data Environment Designer and save it with the form.
The data environment can automate opening and closing tables and views when the form is run. In addition, the data environment helps you set the ControlSource property for controls by populating the ControlSource property setting box in the Properties window with all the fields in your data environment.
To open the Data Environment Designer
From the View menu, choose Data Environment.
1.
From the Shortcut menu, choose Add.
2.
In the Open dialog box, choose a table or view to add to the data environment.
3.
The Data Environment Designer
Common Data Environment Properties
The following data environment properties are commonly set in the Properties window:
Property Description Default Setting
AutoCloseTables Controls whether tables and views are closed
when the form is released. True (.T.)
AutoOpenTables Controls whether tables and views in the data environment are opened when the form is run.
True (.T.)
InitialSelectedAlias Specifies the table or view that is selected
when the form is run. "" at design time. If not specified, at run time the first cursor added to the DataEnvironment is initially selected.
Adding a Table or View to the Data Environment Designer
When you add tables or views to the Data Environment Designer, you can see the fields and indexes that belong to the table or view.
To add a table or view to the Data Environment
From the Data Environment Designer, choose Add from the DataEnvironment menu.
1.
In the Add Table or View dialog box, choose a table or view from the list.
-or-If no database or project is open, choose Other to select a table.
2.
You can also drag a table or view from an open project or the Database Designer into the Data Environment Designer.
When the Data Environment Designer is active, the Properties window displays objects and properties associated with the data
environment. Each table or view in the data environment, each relationship between tables, and the data environment itself is a separate object in the Object box of the Properties window.
Removing a Table from the Data Environment Designer
When you remove a table from the data environment, any relationships that the table is involved in are also removed.
To remove a table or view from the Data Environment Designer In the Data Environment Designer, select the table or view.
1.
From the DataEnvironment menu, choose Remove.
2.
Setting Relationships in the Data Environment Designer
If you add tables to the Data Environment Designer that have persistent relationships set in a database, the relationships are automatically added in the data environment. If the tables don’t have persistent relationships, you can still relate them in the Data Environment Designer.
To set relationships in the Data Environment Designer
Drag a field from the primary table onto the matching index tag in the related table.
The Data Environment Designer with relationships set between tables
●
You can also drag a field from the primary table to a field in the related table. If there is no index tag in the related table corresponding to the field in the primary table, you're prompted to create the index tag.
Editing Relationships in the Data Environment Designer
When you set a relation in the Data Environment Designer, a line between the tables indicates the relationship.
To edit the properties of the relation
In the Properties window, select the relation from the Object box.
●
The properties of the relation correspond to clauses and keywords in the SET RELATION and SET SKIP commands.
The RelationalExpr property is set by default to the name of the primary key field in the primary table. If the related table is indexed on an expression, you need to set the RelationalExpr property to this expression. For example, if the related table is indexed on UPPER(cust_id), you need to set RelationalExpr to UPPER(cust_id).
If the relation is not a one-to-many relationship, set the OneToMany property to false (.F.). This corresponds to using the SET RELATION command without issuing SET SKIP.
Setting the OneToMany property of a relation to true (.T.) corresponds to issuing the SET SKIP command. When you skip through the parent table, the record pointer remains on the same parent record until the record pointer moves through all related records in the child table.
Note If you want a one-to-many relationship in the form, set the OneToMany property to true (.T.), even if a persistent one-to-many relationship has been established in a database.
Creating Single- and Multiple-Document Interfaces
Visual FoxPro allows to you to create two types of applications:
Multiple-document interface(MDI) applications consist of a single main window, and the application’s windows are contained within or float on top of the main window. Visual FoxPro is primarily an MDI application, with the command window, edit windows, and designer windows contained within the main Visual FoxPro window.
●
Single-document interface(SDI) applications consist of one or more independent windows, each of which appears
separately on the Windows desktop. Microsoft Exchange is an example of an SDI application, in which each message you open appears in its own independent window.
●
An application consisting of single window is usually an SDI application, but some applications mix SDI and MDI elements. For example, Visual FoxPro displays its debugger as an SDI application, which in turn contains MDI windows of its own.
To support both types of interfaces, Visual FoxPro allows you to create several types of forms:
Child form. A form contained within another window, used in creating MDI applications. Child forms cannot be moved outside the bounds of their parent form (the main form), and when minimized appear at the bottom of their parent form. If their parent form is minimized, they are minimized along with it.
●
Floating form. A form that belongs to a parent (main) form, but is not contained within it. Instead, floating forms can be moved anywhere on the screen. They cannot be moved behind their parent window. If minimized, a floating form appears at the bottom of the desktop. If their parent form is minimized, floating forms are minimized along with it. Floating forms are also used in creating MDI applications.
●
Top-level form. An independent form without parent form, used to create an SDI application, or to serve as the parent for other child forms in an MDI application. Top-level forms work at the same level as other Windows applications, and can appear in front of or behind them. They appear on the Windows taskbar.
●
Child, floating, and top-level forms
Specifying a Form Type
You create all types of forms in much the same way, but you set specific properties to indicate how the form should behave.
If you're creating a child form, you specify not only that it should appear inside another form, but also whether it is an MDI-compliant child form, which indicates how the form behaves when maximized. If the child form is MDI-compliant, it combines with the parent form, sharing the parent form’s title bar and caption, menus, and toolbars. A child form that is not MDI-compliant maximizes into the full client area of the parent, but retains its own caption and title bar.
To specify a child form
Create or edit the form using the Form Designer.
1.
Set the form’s ShowWindow property to one of the following values:
0 — In Screen. The child form’s parent will be the main Visual FoxPro window.
●
1 — In Top-Level Form. The child form’s parent will be the top-level form that is active when the child window is displayed. Use this setting if you want the child window to appear inside any top-level window other than the main Visual FoxPro window.
●
2.
Set the form’s MDIForm property to .T. (true) if you want the child form to be combined with the parent when maximized, or to .F. (false) if the child window should be retained as a separate window when maximized.
3.
A floating form is a variation of a child form.
To specify a floating form
Create or edit the form using the Form Designer.
1.
Set the form’s ShowWindow property to one of the following values:
0 — In Screen. The floating form’s parent will be the main Visual FoxPro window.
●
2.
1 — In Top-Level Form. The floating form’s parent will be the top-level form that is active when the floating window is displayed.
●
Set the form’s Desktop property to .T. (true).
3.
To specify a top-level form
Create or edit the form using the Form Designer.
1.
Set the form’s ShowWindow property to 2 — As Top-Level Form.
2.
Displaying a Child Form Inside a Top-Level Form
If you've created a child form in which the ShowWindow property is set to 1 — In Top-Level Form, you don't directly specify the top-level form that acts as the child form’s parent. Instead, Visual FoxPro assigns the child form to a parent at the time the child window is displayed.
To display a child form inside a top-level form Create a top-level form.
1.
In the event code of the top-level form, include the DO FORM command, specifying the name of the child form to display.
For example, create a button in the top-level form, and then in the Click event code for the button, include a command such as this one:
DO FORM MyChild
Note The top-level form must be visible and active when the child form is displayed. Therefore, you cannot use the Init event of the top-level form to display a child form, because the top-level form will not yet be active.
2.
Activate the top-level form, and then if necessary, trigger the event that displays the child form.
3.
Hiding the Main Visual FoxPro Window
If you're running a top-level form, you might not want the main Visual FoxPro window to be visible. You can use the Visible property of the Application object to hide and show the main Visual FoxPro window as needed.
To hide the main Visual FoxPro window
In the Init event of the form, include the following line of code:
Application.Visible = .F.
1.
In the Destroy event of the form, include the following line of code:
Application.Visible = .T.
2.
Make sure that you also provide a way to close the form by using THISFORM.Release in some method or event.
Note You can also include the following line in a configuration file to hide the main Visual FoxPro window:
SCREEN = OFF
For more information about configuring Visual FoxPro, see Chapter 3, Configuring Visual FoxPro, in the Installation Guide.
Adding a Menu to a Top-Level Form
To add a menu to a top-level form
Create a top-level form menu. For more information about creating menus for top-level forms, see Chapter 11, Designing Menus and Toolbars.
1.
Set the form’s ShowWindow property to 2 – As Top-Level Form.
2.
In the Init event of the form, run the menu program and pass it two parameters:
DO menuname.mpr WITH oForm, lAutoRename
oForm is an object reference to the form. In the Init event of the form, pass THIS as the first parameter.
lAutoRename specifies whether or not a new unique name is generated for the menu. If you plan to run multiple instances of the form, pass .T. for lAutoRename.
For example, you can call a menu called mySDImenu with this code:
DO mySDImenu.mpr WITH THIS, .T.
3.
Extending Forms with Form Sets
You can manipulate multiple forms as a group by including them in a form set. A form set has these benefits:
You can show or hide all the forms in a form set at one time.
●
You can visually arrange multiple forms at once to control their relative positions.
●
Because all the forms in a form set are defined in a single .scx file with a single data environment, you can automatically synchronize record pointers in multiple forms. If you change the record pointer in a parent table in one form, the child records in another form are updated and displayed.
●
Note All the forms and all the objects on the forms are loaded when you run the form set. Loading many forms with a lot of controls might take several seconds.
Creating a New Form Set
A form set is a parent container for one or more forms. When you are in the Form Designer, you can create a form set.
To create a form set
From the Form menu, choose Create Formset.
●
If you don’t want to work with multiple forms as a group of forms, you don’t need to create a form set. Once you've created a form set, you can add forms to it.
Adding and Removing Forms
Once you've created a form set, you can add new forms and remove forms.
To add additional forms to a form set
From the Form menu, choose Add New Form.
●
To remove a form from a form set
In the Form box at the bottom of the Form Designer, select the form.
1.
From the Form menu, choose Remove Form.
2.
If you have a single form in a form set, you can remove the form set so that you have only the form.
To remove a form set
From the Form menu, choose Remove Formset.
●
Forms are saved in table format to a file with an .scx extension. When you create a form, the .scx table contains a record for the form, a record for the data environment, and two records for internal use. A record is added for each object you add to the form or to the data environment. If you create a form set, an additional record is added for the form set and for each new form. The parent container of each form is the form set. The parent container of each control is the form that it is placed on.
Tip When you run a form set, you may not want all forms in the form set initially visible. Set the Visible property to false (.F.) for forms you don’t want displayed when the form set runs. Set the Visible property to true (.T.) when you want the forms
displayed.