Add Cell Viewing Form (dbExpress Tutorial)

From RAD Studio
Jump to: navigation, search

Go Up to Tutorial: Using dbExpress to View and Update Databases in an Application

A table cell may contain more data than can easily be viewed in the TDBGrid. This application displays a form containing the cell data when you click on a cell.

Add a form to the project by displaying the Project Manager in the right pane. Right-click on the project name DB_CDSDataUpdate and select:

  • Add New > Form - Delphi for Delphi.
  • Add New > Form - C++Builder for C++Builder.

Change the form's Caption to Current Field. Set the Name property to FormCurrentField.

  • For Delphi, save this new unit as cdsfield.pas.
  • For C++, save this new unit as cdsfield.cpp.

We want to display text, so add a TDBMemo component to the form. The TDBMemo component allows viewing and editing a dataset field. Set the TDBMemo's Name to "DBMemoCurrentField". Set all 4 parts of the Anchor property to true, so that when the form is resized, the TDBMemo fills the form.

The form now looks like this figure:

TutorialdbExpressFieldForm.png

When you click a cell in the TDBGrid, this form is resized and displayed with the field value in the TDBMemo. This event handling is described in Clicking on Table Cell.

This form needs to be linked to the main form:

  • For Delphi, add cdsfield to the uses clause of cdsmain.pas.
  • For C++Builder, add this line to cdsmain.h to reference the file just added:
#include "cdsfield.h"

The application is now complete.

Previous

Write Utility Code

Next

Run the Application