Special Steps for Views and CursorAdapters

When you are creating forms that use views or CursorAdapters as data sources, you need to take the following special steps when you create the views, the CursorAdapters and the forms. These steps will have more meaning for you as you learn more about creating forms in VPME. We are presenting the special steps here to emphasize them.

Creating Views and CursorAdapters for Forms

Views and CursorAdapters used with forms need to have special filters set up for them depending on how they will be used. See View Filters and CursorAdapter Filters for detailed descriptions of view and CursorAdapter filter requirements. Three common situations that require special filters are described below.

·       Related Forms Parent - PKValue: If a view or CursorAdapter will be the Initial Selected Alias of a Related Forms parent form (see Creating Forms: Related Forms), the view or CursorAdapter needs to have a filter set on the primary key field or expression (if the primary key is compound) using a variable named "PKValue".

·       Child - ParentPKValue: If the view or CursorAdapter (a) will be used as a child on a One-To-Many form or Related Pages form or (b) will be the InitialSelected Alias of a Related Forms child form, the view or CursorAdapter needs to have a filter set on its foreign key field or expression (if the foreign key is compound) using a variable named "ParentPKValue".

·       Foreign Key Descriptive Expression – PKValue: If the view or CursorAdapter is a Picklist Cursor that will be used to display a descriptive expression for a foreign key in a textbox on a form, the view or CursorAdapter needs to have a filter set on the primary key field or expression (if the primary key is compound) of the view or CursorAdapter using a variable named "PKValue". See Displaying a Descriptive Expression.

Data Environment / Cursor Properties and Methods

When you use a view or CursorAdapter with a form, you may need to set the following Data Environment / cursor properties and add code to the BeforeOpenTables event of the Data Environment.

·       BeforeOpenTables Event: You may need to add up to three lines of code to the BeforeOpenTables event of the Data Environment.

·       Private Data Sessions: When running forms that use a private datasession with views or CursorAdapters, Visual FoxPro will display text that specifies the number of records selected and the time it took to generate the cursor. To prevent this text from appearing in the application window or the currently active window, put the following line of code in the BeforeOpenTables event of the Data Environment:

SET TALK OFF

·       Deleted Records: To prevent deleted records from being included in the view or CursorAdapter cursor, put the following line of code in the BeforeOpenTables event of the Data Environment for every form you create that includes a view or CursorAdapter in the Data Environment:

SET DELETED ON

·       Matching Remote Views: If you are using matching local and remote views with a form, the LocalToRemote method of the application object should be called from the BeforeOpenTables method of the Data Environment of forms and reports that will use remote data. The LocalToRemote method finds each view cursor in the Data Environment and determines if the local or matching remote version of the view should be used. If the matching remote view should be used, the method changes the value in the Database property of the cursor object to the name of the database that contains the matching remote view and the value in the CursorSource properties of the cursor object to the name of the matching remote view.

   If you will be using matching remote data, the BeforeOpenTables event should contain the following code:

_SCREEN.oApp.LocalToRemote(This)

·       NoDataOnLoad Property - Views: You must set every filtered view's Data Environment cursor NoDataOnLoad property to .T. to prevent Visual FoxPro from displaying parameter prompts when a form loads.

·       NoData Property – CursorAdapters: When you use a filtered CursorAdapter with a form, you must set the CursorAdapter’s Data Environment cursor NoData property to .T. to prevent Visual FoxPro from displaying prompts when a form loads.

Form Properties

When you use a view or CursorAdapter with a form, you may need to set the following form properties

·       cInitialTag Property: You can set the initial order for an InitialSelectedAlias (ISA) table through the Order property of the Cursor. You cannot do that if the ISA is a view or CursorAdapter. For that reason, we created the cInitialTag property for VPME forms. In the cInitialTag property you put the Tag Name as shown in the Data Builder for the tag definition that you want to use to set the initial order for a view or CursorAdapter ISA. If you like, you can also use this property to set the order for ISA tables instead of the Order property of the Cursor.

·       SQL Find Form – lStartWithFind Property: If the InitialSelectedAlias for a form is a filtered view or CursorAdapter that uses the special FIND<field name> variable, you can choose to display the VPME SQL Find Form at form startup by setting the form's lStartWithFind property to .T.

   You can also set other form properties that control the behavior of the SQL Find Form. See Find – SQL to learn about the form properties that you can set to control the SQL Find Form.

 

More:

How to Create a Form: The Details