Record-Level Data-Driven Developer Code

Tip: This section applies to tables, views and CursorAdapters. This section’s topic is not one on which you need to spend much time as you are learning VPM Enterprise, but you should be aware that the functionality covered exists so that you can use it when you need it.

You can store Visual FoxPro code in the VPME data dictionary for tables, views and CursorAdapters that is run in conjunction with adding, copying, deleting, restoring and saving records. We call this record-level, data-driven developer code.

Select a table in the treeview on the Data Builder List Page, click the Edit page, then click the Code page to see the fourteen record-level functions for which you can enter code.

When you click the check box for one of the record-level functions, the main window on the Code page becomes editable with the line “LPARAMETERS stcRulesID,stoCallingObject” entered. Leave the LPARAMETERS line as is and add your code after it.

The code you enter is stored in memo fields in the Table, View and CursorAdapter Data table, SDATADDTV.DBF. The code is executed using the EXECSCRIPT() function.

Record-Level Functions Code Entry

The record-level functions for which you can enter code are described below along with tips for using the code.

·       Add Record

·       PreAdd: Enter code that you want to run before a new record is created.

·       PostAdd: Enter code that you want to run after a new record is created.

Code Tip: Returning .F. in your PreAdd or PostAdd code cancels the Add.

·       Copy Record

·       PreCopy: Enter code that you want to run before a record is copied.

·       PostCopy: Enter code that you want to run after a record is created by copying an existing record.

Code Tip: Returning .F. in your PreCopy or PostCopy code cancels the Copy.

·       Delete Record

·       PreDelete PreTransaction: Enter code that you want to run before a record is deleted and before the transaction has begun.

·       PreDelete: Enter code that you want to run before a record is deleted but after the transaction has begun.

·       PostDelete: Enter code that you want to run after a record is deleted but before the transaction has ended.

·       PostDelete PostTransaction: Enter code that you want to run after a record is deleted and after the transaction has ended.

Code Tip: Returning .F. in your PreDelete or PostDelete code cancels the Delete.

Code Tip – PreDelete PreTransaction: Can be used when PreDelete cannot be used (for example, when a REQUERY() needs to be performed. Returning .F. cancels the Delete.

Code Tip – PostDelete PostTransaction: Can be used to update another cursor that is not part of the all-or-nothing functionality within the transaction.

·       Restore Record

·       PreRestore: Enter code that you want to run before a record is reverted.

·       PostRestore: Enter code that you want to run after changes to a record are reverted.

·       Save Record

·       PreSave PreTransaction: Enter code that you want to run before a record is saved and before the transaction has begun.

·       PreSave: Enter code that you want to run before a record is saved but after the transaction has begun.

·       PostSave: Enter code that you want to run after a record is saved but before the transaction has ended.

·       PostSave PostTransaction: Enter code that you want to run after a record is saved and after the transaction has ended.

Code Tip: Returning .F. in your PreSave or PostSave code cancels the Save.

Code Tip – PreSave PreTransaction: Can be used when PreSave cannot be used (for example, when a REQUERY() needs to be performed. Returning .F. cancels the Save.

Code Tip – PostSave PostTransaction: Can be used to update another cursor that is not part of the all-or-nothing functionality within the transaction.

Parameters

The parameters passed to record-level functions for which you can enter code are described below along with tips for using the parameters.

·       stcRulesID: Passes the cRulesID form property value. You can use the cRulesID form property to store a value that is passed to your record-level code.

·       For example, if your record-level code needed to know, say, the current application user’s Status, you can store the user’s status in the cRulesID form property and it will be passed to your code. For the user properties available to you, see Error! Reference source not found..

·       stoCallingObject: Passes the object reference of the data handling object. You can use this object reference to access the methods of the data handling object in your code.

·       For example, to access the OpenTable method of the data handler, your code could use the method call  “stoCallingObject.OpenTable(parameters)” where “parameters” is the parameters list expected by the OpenTable method. See the Data Handler Class chapter in the VPME 9.1 Technical Reference manual to learn about the data handler methods available to you.

Remote Data Considerations

If code in the PreSave, PostSave, PreDelete, or PostDelete functions make changes to remote data, those changes are made within a transaction. Therefore, when the transaction is committed or rolled-back, those remote data changes must also be committed or rolled-back. That will happen automatically as long as a different connection is not used to make those changes. If a different connection is used, that connection can be included in the SQLCOMMIT or SQLROLLBACK that is executed.

Tip: There is a property of _SCREEN.oApp, cAdditionalConnectionHandles, that can be used to include additional connections in the SQLCOMMIT or SQLROLLBACK. For more than one additional connection, separate the connection handles with commas in the property.

More:

Candidate Keys - Preventing Duplicate Values