Switch to: V9V8V7V6V5

Lesson 4 - Import Forms

In this lesson, you will learn how to use one form from another using the import mechanism. The main form will show the data from the “actor” table, the imported form will add a new record to this table.

These example lessons make use of a version of the well known Sakila database, the successor to Microsoft's Northwind database. While in this lesson we use a version of Sakila adapted to Valentina DB, the skills are transferable to any other database.

Archives

  • Sakila - Here you can find archives of 'sakila' databases for Valentina DB.

Note, that form uses 'sakila' database with Foreign Key links, download and uncompress it.

  • Project from the previous lessons, download and uncompress it.

Step 1: Open Project

Open an existing local project.

  • On the Start Page click Open Project → Local… and select the project on disk.

Step 2: Create Main Form

The main form will contain a TableView control and a button to show the second form.

  • Click Create → Form… to open the wizard.
  • Input the name “actors” and select the “valentina_sakila” datasource.

  • Select the “actor” table and move all fields to the right list.

  • Select the Tabular option to show records in the grid.

The following form will be generated:

  • Adjust the size of the form to fit more columns.
  • Place the ToolButton control below the grid, set icon and title for in the Property Inspector.

Action for this button will be assigned later after the creation of the child form.

Step 3: Create Child Form

The second form will add a record to the table “actors”

  • Click Create → Form….
  • Input the name “add_actor” and select the “valentina_sakila” datasource.

  • Select the “actor” table and move “first_name” and “last_name” fields to the right list to show them in the form. The rest of the fields are filled automatically.

  • Select the Add option as the data mode.

The following form will be generated:

This form must be hidden automatically if the record is added successfully. Modify the Add button to include call of accept() method.

  • Open the script editor for the clicked slot of the button.

  • Modify the script to call the accept() method. addRecord returns an error in a case of error, so it is necessary to check its result.

Step 4: Import Form

  • Switch to the “actors” form tab.
  • Set an action Show Dialog for the New Actor… button.

  • Select the “add_actor” form.

Step 5: Execute Form

  • Click Execute and scroll to the last record.

  • Click New Actor… button, input data in the shown form and click Add.

  • Scroll down and view the added record.

The resulting project you can find here.