 Lesson 4: Working with Forms

So far in this tutorial you have created a table for the new video orders placed by customers of Training By Design. You have also created a data model linking the CUSTOMER.DB, ORDERS.DB, and VIDEO.DB tables. You are now going to create forms that will make it possible to enter new data into those tables and easily view the data. You are going to create a New Customer Information form, a New Video Order form, and a form that links to these two forms. 

In this lesson, you will

  create three new forms
  
  create a calculated field
  
  use the Designer window to customize your form
  
You will need about 30 minutes to complete this lesson.

To see what your completed forms will look like, click here for Form 1, Form 2, and Form 3.

Note

  Make sure your working directory is set to the folder where you saved the Tutorial sample files. If necessary, see "Setting your current working directory" in Lesson 2 for more information.
  
Creating a new form

Forms provide you with an efficient way of viewing, entering, and editing records in your tables, and are particularly useful when working with linked tables. Once you design a form, you don't have to open several tables to enter or edit information that is stored in many different files. Any change you make to the data in the form is reflected in the table. 

To create a form

1.	Click File menu, New, Form.

2.	In the New Form dialog box, click Blank.

3.	Right-click the form's Title Bar and choose Window Style.

4.	In the Window style section, enable Window.

5.	In the Title box, type Training By Design.

6.	Accept the default property settings.

7.	Click OK.

Adding objects to a form

When you create a form from scratch, you add objects and properties to customize the format of the form. You can group certain fields together to make data entry more efficient, and you can add boxes or color to make the form more attractive. Paradox provides a variety of tools in the Form Design window to give you great flexibility with your form. Each item on your form - headings, table frames, boxes, text, fields, buttons - is an object. You can select any object and move or delete it, or right-click an object to access that object's properties. In the steps that follow, you will work through a few of the customizing options.

To add buttons

1.	On the Design Object toolbar, click the Button object button.

2.	Click in the Form window to place the Button object.

3.	In the Button Expert dialog box, click Cancel.

Experts are an easy and efficient tool for creating objects. For this tutorial, however, you will manually create the button objects.

To resize a button

1.	Select the button.

2.	Click View menu, Size and Position.

3.	Click Format menu, Design Setup.

4.	In the Grid section under Units, select inches from the list box.

5.	Click OK.

6.	Select the frame of the button and resize it to 2.50 x .65 inches.

You can see the size and position of the button in the status bar. 

To add another button

1.	Select the button and click Edit menu, Duplicate.

2.	Right-click the first button and choose Properties.

3.	On the General Page, type NewCust in the Name of object box.

4.	Click Apply.

5.	Right-click the second button and choose Properties.

6.	On the General Page, type NewOrder in the Name of object box.

7.	Click OK.

To change button labels

1.	Select the text label of NewCust by clicking the text until a flashing cursor appears.

2.	Re-label the button as Add New Customer.

3.	Select the text label of NewOrder.

4.	Re-label the button as Place New Video Orders.

5.	Select the text label of NewCust.

6.	On the Text formatting toolbar, select a font and size for the label.

7.	Select the text label of NewOrder.

8.	On the Text formatting toolbar, select a font and size for the label.

Adding a text object

Using text objects in forms and reports, you can add labels, provide instructions, and create titles. You can change the formatting, alignment, color, font, and wrapping of the text. Text objects can be placed separately on a form using the Text tool; or, they can appear automatically as part of another design object, for example, as a label in a field or as a heading in a table frame.

To add text to the form

1.	On the Design Object toolbar, click the text button.

2.	Click on the form to place the text box above the two buttons.

3.	Follow each of the steps in the Text Expert dialog box to enter the following text:

"Training By Design"

The Text Expert will guide you through choosing the desired typeface, size, style, and color. It will also help you select special effects and alignment for the text.

To resize the form window

1.	Select the form page.

2.	Use the scroll bars so you can see the bottom right corner of the frame.

3.	Select the bottom right frame marker.

4.	Resize the page window by dragging the corner frame marker. Resize the frame so that the buttons and title are in the center of the page.

There are several other properties that you can apply to the form. Right-click any object on the form (including the form window itself) and choose Properties. In the Properties dialog box you can specify the design, color, pattern, and many more properties. The following form is just an example of how your form can look.



Defining buttons

If you were to run the form that you just created, it wouldn't do anything. You could push the buttons that you added to the form, but they wouldn't activate anything. It's important to understand that for every object you create, and for every event that affects an object, Paradox has a default response. In some cases, Paradox's default response is something you can see, such as a button moving when you click it. In other cases, the Paradox default response is not visible, but it's necessary nonetheless. If the default response is not enough, you can use ObjectPAL code to define exactly what you want the object to do. 

ObjectPAL is the Paradox database-application development language. You use ObjectPAL by attaching methods, which are pieces of ObjectPAL code, to objects on a form. You can create methods that manipulate data, respond to actions, and perform functions. You are going to add ObjectPAL code to define a function for the button objects. 

To add ObjectPAL code

1.	Right-click NewCust and choose Object Explorer.

2.	On the Events page, double-click pushbutton.

3.	In the Editor window, type the following code:

method pushbutton (var eventInfo Event)
	var
		custForm Form
	endvar
	custForm.open("NewCust.fsl")
endmethod

4.	Close the Editor window.

5.	Right-click NewOrder and choose Object Explorer.

6.	On the Events page, double-click pushbutton.

7.	In the Editor window, type the following code:

method pushbutton (var eventInfo Event)
	var
		custForm Form
	endvar
	custForm.open("OrderForm.fsl")
endmethod

8.	Close the Editor window.

Now when you run the form and click on a pushbutton, you will call the ObjectPAL method and open the corresponding form.

To Save the Form

1.	Click File Menu, Save As.

2.	In the File Name box type LINK.

Paradox saves the form with the default extension *.FSL. 

3.	Click Save.

Note

  This is a very simple example of using ObjectPAL. For more information, see the additional references provided by Paradox. Click Help menu, ObjectPAL Reference or click Help menu, ObjectPAL Tutorial.
  
Creating a form based on a table

You will now create a form based on the CUSTOMER.DB table. If Training By Design has a new customer, they will need to update their records and enter the new information into the CUSTOMER.DB table.

To create a form based on a table

1.	Click File menu, New, Form.

2.	In the New Form dialog box, click Data Model.

3.	From the table list, double-click CUSTOMER.DB and click OK.

4.	In the Design Layout dialog box, click the Style Sheet list box and choose FACTORY.FT.

5.	Click OK.

To define form properties

1.	Right-click the form's Title Bar and choose Window Style.

2.	In the Window style section, enable Window.

3.	In the Title box, type New Customer.

4.	Accept the default property settings and click OK.

To resize the form window

1.	Select the form page.

2.	Use the scroll bars so you can see the bottom right corner of the frame.

3.	Select the bottom right frame marker and resize the page window by dragging the corner frame marker. Resize the frame so that it surrounds the fields in the form.

To save the form

1.	Click File menu, Save As.

2.	In the File name box, type NewCust.

3.	Click Save.

When you are finished, the form should look similar to the following:



Creating a form based on multiple tables

When creating a form based on more than two tables, you must have already created a data model. In this lesson, you'll be using the TBDform.DM data model you created in the previous lesson. 

To create a form

1.	Click File menu, New, Form.

2.	In the New Form dialog box, choose Data Model.

3.	From the Type list box on the bottom of the dialog box, click the down arrow and choose Data Models.

4.	In the file list box, double-click TBDform.DM to display the data model on the right side of the dialog box.

5.	Click OK.

The Design Layout window appears. It allows you to make changes to your form layout.

Using the Design Layout dialog box

The Design Layout dialog box contains two pages of design layout options: 

  Layout - allows you to set the layout (columns, rows) and style (single record, tabular, multi-record or blank) or choose a style sheet for the form.
  
  Fields - allows you to remove unwanted fields from your form.
  
If you were to create a one-to-many relationship, the Design Layout dialog box would contain a third page: Detail Tables. The Detail Tables page lets you change the layout of detail and multi-record tables. Since you are using a data model with a one-to-one relationship, you do not see this page.

The display window on the right dynamically illustrates the effect your layout selections have on the form design. 

To define the fields for your form

1.	In the Design Layout dialog box, click the Fields tab.

2.	From the Tables list box, select ORDERS.DB.

3.	Under Selected fields, use the Remove Field button to remove all fields except the following:

  ORDERS.OrderNo
  
  ORDERS.CustomerID
  
  ORDERS.ItemNo
  
  VIDEO.Title
  
  ORDERS.Qty
  
  VIDEO.Price
  
If you remove the wrong field, you can use the Reset Fields button to recover all of the fields. 

4.	Use the Order arrows to put the fields in the order listed above.

To define the layout for your form

1.	Click the Layout tab.

2.	In the Field Layout section, enable By rows.

3.	In the Style section, enable Multi-record.

4.	In the Multi-record layout section, enable Vertical.

5.	Click OK.

To save the form

1.	Click File menu, Save As.

2.	In the FileName box, type OrderForm.

Paradox automatically saves the Form with the appropriate file extension (*.FSL or *.FDL)

3.	Click Save.

Customizing your form

You can customize your form by adding objects and defining properties to make the form more efficient and attractive. For ORDERFORM.FSL, you will add a new field and then define it as a calculated field. You will also customize the form by adding text. Make sure ORDERFORM.fsl is open in the Design form window. If it isn't, click View menu, Design Form.

To set the style of the form

1.	Right-click the Title Bar of the form and choose Window style.

2.	Under Window style, enable Window.

3.	In the Window properties section, type Video Order in the Title box.

4.	Click OK.

To add a field to a form

1.	Select the Multirecord page and click and drag the frame to resize it so that you create room for a title at the top of the form and an additional field to the right of the Price field. (see below)

You will know that the Multirecord page is selected when the Status Bar shows ORDERS [Multirecord]. 

2.	Select the first record and click and drag the record frame to resize it to create room for an additional record beside the Price field (see below).

3.	Select the price field and click Edit menu, Copy.

4.	Select the record and click Edit menu, Paste.

5.	Click the new field's label twice to rename the field Total Price. 

6.	Select the Total Price field, press SHIFT, and click the Price field.

7.	On the Align toolbar, click the Align Top button.

If you don't see the Align toolbar, right-click any toolbar and select Align.

8.	Use the arrows keys to align the new field beside the Price field (see the finished form below).

To change field properties

1.	Right-click the Total Price field and choose Properties.

2.	In the Name of object box type TotalPrice.

3.	Click OK.

To add text

1.	On the Design Object toolbar, click the Text Tool.

2.	Click on the form above the first record.

You may have to click and drag the form frame to create room for the text above the first record.

3.	Follow each of the steps in the Text Expert dialog box to enter the following text:

"Video Order Form"

The Text Expert will guide you through choosing the desired typeface, size, style, and color, and selecting a special effect and alignment.

Click here to see what the form should look like when you are finished.

To save the form

  Click File menu, Save.
  
Note

  There are a number of other customizing options that you can apply to your form. For example, to move an object, select the object and drag it to a new position on the form. You can experiment with the Properties of your objects and add new objects. If you add a new object, then decide that you no longer want it on the form, select the object and press DELETE. 
  
Defining fields for your form

To make the most efficient use of hard drive space when you are planning a database, you do not want to include fields in a table that the system can easily create for you. Paradox allows you to add a field to your form and define it to store a value based on a calculation. Fields such as sums, averages, sub-totals, and totals can be created as defined fields.

Defined fields can also store the concatenation of two or more alpha fields. For example, on a form, you may want to use the full name for a customer. This would be separated into the title, first and last name fields in your table. By creating a defined field, you can automatically combine the data from these fields in one field on your form.

For this lesson, you will create a calculated field for Total Price. You will tell Paradox to multiply the Price field from the VIDEO.DB table with the total quantity requested in the QTY field of ORDERS.DB. You will also define a common property for all the fields in the form at one time.

To create a calculated field

1.	Make sure the ORDERFORM.FSL is open in Design Form mode.

2.	In the Design Form window, select the Total Price field.

You will first have to click the entire field, and then click once more to select the edit region.

3.	Right-click the edit region and choose Define Field.

4.	In the Define Field Object dialog box, enable Calculated.

5.	In the Calculated box, enter the following expression:

[ORDERS.Qty]*[VIDEO.Price]

6.	Click OK.

The expression you entered tells Paradox to multiply the ORDERS.Qty field value with the VIDEO.Price field value, and enter that value into the Total Price field.

To define field properties

1.	Select the OrderNo field.

2.	Press SHIFT and select all the other fields. 

3.	Right-click the fields and choose Properties.

4.	Click the Text tab.

5.	On the Text page, enable Center in the Alignment section.

6.	Click OK.

To save the form

  Click File menu, Save.
  
Summary of Lesson 4

In this lesson you learned how to

  create new forms 
  
  create a new form based on a data model
  
  customize the forms using the Form Designer Window
  
  define fields for your forms
  
In Lesson 5 you'll learn how to enter data using forms and lookup tables.

Finished form 1



Finished form 2

Finished form 3








