Contents:

 

 

Introduction


News blog


What is Servoy?


Getting Started


Comparison Servoy/VFP


Performance


How-To's

 

Code Reference

 

VFP2Servoy Toolkit

 

 

Contact / feedback

 

 

 

 

 

 

 

 

 

 

 

 

 

 

How to use form inheritance



In this walkthrough we will create a sample in which we build a parent form that contains navigation logic. Additionally we will create customer- and employee subforms (subclasses based on frmNavigate) that make use of this changed behaviour.

We will use the example_data database in this walkthrough.

  • Create a new form
  • Set the form name to frmNavigate
  • Set the DataSource to -none-

Create a form without a datasource


  • Press Next
  • Uncheck the Place horizontal checkbox
  • Press Finish

Form dialog


  • Place several buttons along top of the form as in the image below
  • Set the text property of the buttons accordingly

Add navigation buttons


  • Select the New button
  • Doubleclick in the value area of the onAction event
  • In the dialog click the Create Form Method button
  • Type NewRecord and press Ok

Create NewRecord form method


  • Make sure that the newly created method is bound to the corresponding button as shown in the image below
  • Do the same for all other buttons and create the following methods: EditMode, FindMode, SaveChanges, CancelChanges, FirstRecord, PreviousRecord, NextRecord and LastRecord
  • Also add a SetFormReadOnly to the onShow event

Bind NewRecord method to the newButton


Now lets add some code. The first thing we want to take care of is making the form ReadOnly so that users can't make changes until they press the Edit button. Locate the SetFormReadOnly method and add the following code:

SetFormReadOnly methode code


This makes sure that the fields showing data are readonly and that changes to the data will not be save automatically. Next we want to add code to the NewRecord button:

New record code


Whenever the user wants to make changes to the data he will press the Edit button and we will enable the fields by adding only one line of code to the EditMode method:

Edit mode


To save changes we have to tell the databaseManager to do so. At the same time we want to disable the fields for further changes again:

Save changes


If the user wants to undo the changes (even to multiple records) then we will have to a rollback and make the fields readonly again:

Cancel changes


Finally we want to add the code for navigating through the records:

First record


Previous record


Next record


Last record



Ok, now we are finished with implementing our basic form navigation in the parent form frmNavigate. Now lets subclass it (Servoy calls this extending).

  • Select the example_data database in the Solution Explorer
  • In the List View locate the customers table and right-click it
  • From the popup-menu select Create new form

  • Enter frmSubCustomer as the form name
  • The datasource should be set to example_data.customers
  • Important! Set the extends property to frmNavigate.

Create frmSubCustomer based on frmNavigate


  • Select a few fields for editing
  • Uncheck the Place horizontal checkbox
  • Press the Finish button

Form dialog


Form designer frmSubCustomer


Notice the red dotted lines around the buttons in the form designer. This tells you which elements were inherited from the parent form. Now lets do the same for the employee form:

  • Select the example_data database in the Solution Explorer
  • In the List View locate the employees table and right-click it
  • From the popup-menu select Create new form

  • Enter frmSubEmployee as the form name
  • The datasource should be set to example_data.employees
  • Important! Set the extends property to frmNavigate.

Create frmSubEmployee based on frmNavigate


  • Select a few fields for editing
  • Uncheck the Place horizontal checkbox
  • Press the Finish button

Form dialog


Form designer frmSubEmployee



Start the application and play with both forms. As you can see we have now abstracted the forms navigation controls into the parent form frmNavigate. Little code was needed to change the default way Servoy handles data. In the subforms we didn't write any code at all!

Smart client


Conclusion

This walkthrough demonstrates Servoy's ease of use and it's powerful features at the same time!

The samples work in both the smart-client and in the web-client with one exception. In the web-client setting the form in Find-mode won't let you start a search. For this reason you may want to add a search button that starts the search in the web-client and is hidden in the smart-client. You may also want to add a delete button and use graphics on the buttons.

External resources:

 

vfp plugin

 

ServoyWorld 2012 pics

 

Official Servoy website

 

Ken Levy on Servoy

 

Servoy info

 

Servoy Forum

 

Servoy Documentation

 

VisualFoxpro.com © 2010-2012 • All rights reserved • Contact: info@visualfoxpro.com