RAD Studio
ContentsIndex
PreviousUpNext
Using data controls
Name 
Description 
Data controls connect to datasets by using a data source. A data source component (TDataSource) acts as a conduit between the control and a dataset containing data. Each data-aware control must be associated with a data source component to have data to display and manipulate. Similarly, all datasets must be associated with a data source component in order for their data to be displayed and manipulated in data-aware controls on a form.
Note: Data source components are also required for linking unnested datasets in master-detail relationships.
 
When you build the user interface for your database application, you have choices to make about how you want to organize the display of information and the controls that manipulate that information.
One of the first decisions to make is whether you want to display a single record at a time, or multiple records.
In addition, you will want to add controls to navigate and manipulate records. The TDBNavigator control provides built-in support for many of the functions you may want to perform. 
In Associating a Data Control with a Dataset, the datasource was associated with its dataset by setting the DataSet property at design time. At runtime, you can switch the dataset for a data source component as needed. For example, the following code swaps the dataset for the CustSource data source component between the dataset components named Customers and Orders:  
TDBRadioGroup is a data-aware version of a radio group control. It enables you to set the value of a data field with a radio button control where there is a limited number of possible values for the field. The radio group includes one button for each value a field can accept. Users can set the value for a data field by selecting the desired radio button.
The Items property determines the radio buttons that appear in the group. Items is a string list. One radio button is displayed for each string in Items, and each string appears to the... more 
When your application iterates through a dataset or performs a search, you should temporarily prevent refreshing of the values displayed in data-aware controls each time the current record changes. Preventing refreshing of values speeds the iteration or search and prevents annoying screen-flicker.
DisableControls is a dataset method that disables display for all data-aware controls linked to a dataset. As soon as the iteration or search is over, your application should immediately call the dataset's EnableControls method to re-enable display for the controls.
Usually you disable controls before entering an iterative process. The iterative process itself should take place inside a... more 
There are four data controls that provide the user with a set of default data values to choose from at runtime. These are data-aware versions of standard list and combo box controls:
  • TDBListBox, which displays a scrollable list of items from which a user can choose to enter in a data field. A data-aware list box displays a default value for a field in the current record and highlights its corresponding entry in the list. If the current row's field value is not in the list, no value is highlighted in the list box. When a user selects a list... more 
Lookup list boxes and lookup combo boxes (TDBLookupListBox and TDBLookupComboBox) present the user with a restricted list of choices from which to set a valid field value. When a user selects a list item, the corresponding field value is changed in the underlying dataset.
For example, consider an order form whose fields are tied to the OrdersTable. OrdersTable contains a CustNo field corresponding to a customer ID, but OrdersTable does not have any other customer information. The CustomersTable, on the other hand, contains a CustNo field corresponding to a customer ID, and also contains additional information, such as... more 
TDBEdit is a data-aware version of an edit box component. TDBEdit displays the current value of a data field to which it is linked and permits it to be edited using standard edit box techniques.
For example, suppose CustomersSource is a TDataSource component that is active and linked to an open TClientDataSet called CustomersTable. You can then place a TDBEdit component on a form and set its properties as follows:
  • DataSource: CustomersSource
  • DataField: CustNo
The data-aware edit box component immediately displays the value of the current row of the CustNo column of the CustomersTable dataset, both at... more 
TDBImage is a data-aware control that displays graphics contained in BLOB fields.
By default, TDBImage permits a user to edit a graphics image by cutting and pasting to and from the Clipboard using the CutToClipboard, CopyToClipboard, and PasteFromClipboard methods. You can, instead, supply your own editing methods attached to the event handlers for the control.
By default, an image control displays as much of a graphic as fits in the control, cropping the image if it is too big. You can set the Stretch property to True to resize the graphic to fit within an image control as it is... more 
TDBMemo is a data-aware component—similar to the standard TMemo component—that can display lengthy text data. TDBMemo displays multi-line text, and permits a user to enter multi-line text as well. You can use TDBMemo controls to display large text fields or text data contained in binary large object (BLOB) fields.
By default, TDBMemo permits a user to edit memo text. To prevent editing, set the ReadOnly property of the memo control to True. To display tabs and permit users to enter them in a memo, set the WantTabs property to True. To limit the number of characters users can... more 
TDBRichEdit is a data-aware component—similar to the standard TRichEdit component—that can display formatted text stored in a binary large object (BLOB) field. TDBRichEdit displays formatted, multi-line text, and permits a user to enter formatted multi-line text as well.
Note: While TDBRichEdit provides properties and methods to enter and work with rich text, it does not provide any user interface components to make these formatting options available to the user. Your application must implement the user interface to surface rich text capabilities.
By default, TDBRichEdit permits a user to edit memo text. To prevent editing, set the ReadOnly property of the... more 
TDBText is a read-only control similar to the TLabel component on the Standard category of the Tool palette. A TDBText control is useful when you want to provide display-only data on a form that allows user input in other controls. For example, suppose a form is created around the fields in a customer list table, and that once the user enters a street address, city, and state or province information in the form, you use a dynamic lookup to automatically determine the zip code field from a separate table. A TDBText component tied to the zip code table could... more 
All data controls except the navigator display data from a database field. In addition, you can use them to edit and update data as long as the underlying dataset allows it.
Note: Unidirectional datasets never permit users to edit and update data.
The following topics describe how to allow users to edit data using data controls:  
A data control can only post edits to its associated dataset if the dataset's CanModify property is True. CanModify is always False for unidirectional datasets. Some datasets have a ReadOnly property that lets you specify whether CanModify is True.
Note: Whether a dataset can update data depends on whether the underlying database table permits updates.
Even if the dataset's CanModify property is True, the Enabled property of the data source that connects the dataset to the control must be True as well before the control can post updates back to the database table. The Enabled property of... more 
The data source has an Enabled property that determines if it is connected to its dataset. When Enabled is True, the data source is connected to a dataset.
You can temporarily disconnect a single data source from its dataset by setting Enabled to False. When Enabled is False, all data controls attached to the data source component go blank and become inactive until Enabled is set to True. It is recommended, however, to control access to a dataset through a dataset component's DisableControls and EnableControls methods because they affect all attached data sources. 
A dataset must be in dsEdit state to permit editing to its data. If the data source's AutoEdit property is True (the default), the data control handles the task of putting the dataset into dsEdit mode as soon as the user tries to edit its data.
If AutoEdit is False, you must provide an alternate mechanism for putting the dataset into edit mode. One such mechanism is to use a TDBNavigator control with an Edit button, which lets users explicitly put the dataset into edit mode. For more information about TDBNavigator, see Navigating and manipulating records. Alternately,... more 
The Enabled property of a data control determines whether it responds to mouse, keyboard, or timer events, and passes information to its data source. The default setting for this property is True.
To prevent mouse, keyboard, or timer events from reaching a data control, set its Enabled property to False. When Enabled is False, the data source that connects the control to its dataset does not receive information from the data control. The data control continues to display data, but the text displayed in the control is dimmed. 
TDBCheckBox is a data-aware check box control. It can be used to set the values of Boolean fields in a dataset. For example, a customer invoice form might have a check box control that when checked indicates the customer is tax-exempt, and when unchecked indicates that the customer is not tax-exempt.
The data-aware check box control manages its checked or unchecked state by comparing the value of the current field to the contents of ValueChecked and ValueUnchecked properties. If the field value matches the ValueChecked property, the control is checked. Otherwise, if the field matches the ValueUnchecked property, the control... more 
The Refresh method for a dataset flushes local buffers and re-fetches data for an open dataset. You can use this method to update the display in data-aware controls if you think that the underlying data has changed because other applications have simultaneous access to the data used in your application. If you are using cached updates, before you refresh the dataset you must apply any updates the dataset has currently cached.
Refreshing can sometimes lead to unexpected results. For example, if a user is viewing a record deleted by another application, then the record disappears the moment your application calls... more 
Because the data source provides the link between the data control and its dataset, it mediates all of the communication that occurs between the two. Typically, the data-aware control automatically responds to changes in the dataset. However, if your user interface is using controls that are not data-aware, you can use the events of a data source component to manually provide the same sort of response.
The OnDataChange event occurs whenever the data in a record may have changed, including field edits or when the cursor moves to a new record. This event is useful for making sure the control... more 
The following tasks are common to most data controls: Data controls let you display and edit fields of data associated with the current record in a dataset. The following table summarizes the data controls that appear on the Data Controls category of the Tool palette.
Data controls  
When using TDBListBox or TDBComboBox, you must use the String List editor at design time to create the list of items to display. To bring up the String List editor, click the ellipsis button for the Items property in the Object Inspector. Then type in the items that you want to have appear in the list. At runtime, use the methods of the Items property to manipulate its string list.
When a TDBListBox or TDBComboBox control is linked to a field through its DataField property, the field value appears selected in the list. If the current value is... more 
The Data Controls category of the Tool palette provides a set of data-aware controls that represent data from fields in a database record, and, if the dataset allows it, enable users to edit that data and post changes back to the database. By placing data controls onto the forms in your database application, you can build your database application's user interface (UI) so that information is visible and accessible to users.
The data-aware controls you add to your user interface depend on several factors, including the following:
  • The type of data you are displaying. You can choose between controls that... more 
Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!