Simple demo of Customer/Orders one to many form with conflict detection and resolution

Often I’m asked to demo Foxpro to people who’ve never seen it before. In one demo I show how simple it is to create a usable one to many form that allows multiple instances with collision detection and resolution.

  • From the main menu choose File->New->Form
  • In the property sheet, change BufferMode to optimistic and DataSession to 2 (Private)
  • From the main menu choose View->Data Environment (or right click on the form)
  • Navigate to some sample data like Samples\Northwind or Samples\Data
  • Add Customer and Orders tables. Notice that the relationship between these tables is displayed (you can even click on the relationship line and see its properties in the property sheet.
  • Close the “Add Table or View dialog”
  • Multiple select some fields of the Customer table and Right-Click drag to the form.
  • Choose “Create Multiple Controls Here” from the drag context menu. This adds labels and textboxes to the form.
  • Click/drag the orders table to the form. This adds a grid.
  • You can resize the form or contained objects as desired.
  • Click on the “View Classes” library button on the Form Controls Toolbar, choose Add and navigate to the FFC\_datanav.vcx Visual Class library.
  • Choose the “_datanav” buttons object and put it on the form. It will have First, Forward, Rewind, and Last buttons on it.

Save the form as “form1”

Do this twice to get 2 forms: From the command window, DO FORM form1

Move the 2 instances of the form around so you can see both. Click on the navigate buttons to show that the one to many feature works fine.

Now navigate to the same customer record in each form, make a different change in each, and a messagebox comes up:

---------------------------

Data Conflict

---------------------------

A value has been changed by another user.

Field: CONTACT

Record Number: 4

Original Value: Thomas Hardy

Current Value: Thomas Hardy2

Your change: Thomas Hardy1

Do you want to overwrite the current value with your change?

(Choose 'Cancel' to restore the original value.)

---------------------------

Yes No Cancel

---------------------------

At this point, I ask the audience “How many lines of code are needed to create a one to many form with collation detection?” Also notice that you can create useful things in Foxpro without first having to create a project and decide what kind of project it’s going to be.

I’ve been giving this demo for over 10 years since VFP 3.0

Notes:

  • you can hit Ctrl-E to close the form designer and run the form. When you close the form, it will return to the designer. If you run two instances of the form, and you close the first instance, it will try to return to design mode, and you might get a “File is in use” error, because it’s in use by the other form.
  • Beware if you change the primary key (like Customerid). You can lose the related records or violate triggers