16th chapter-Application and programming of data browsing Parts (II.) (2)

Source: Internet
Author: User

Events and applications of 16.4.2 Tdbgrid components

Tdbgrid parts in the same time with many important attributes, Delphi also gave it a number of events to control the user in the Tdbgrid part of the operation, we have some of these events to write handlers, can effectively control the behavior of Tdbgrid parts. Because at one time in the Tdbgrid part is displaying multiple fields in multiple records and records, perhaps in practical applications, different users have their own special needs, such as just changing the value of one of the columns or controlling the user to access only the columns specified in the grid at a time, and so on. Table 16.7 lists the main events and purposes of the Tdbgrid components.

Table 16.7 main events in Tdbgrid parts

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Use of event nomenclature

────────────────────────────────

Oncolentor triggers the event when the user enters the grid columns

Oncolexit triggers the event when the user leaves the grid columns

OnDblClick when the user double-clicks the left mouse button in the grid, the event is triggered

Ondragdrop triggers the event when a user drags the mouse in a grid

OnDragOver when a user drags a grid with the mouse in the grid, the event is triggered

Ondrawdatacell is used to customize the grid units in the drawing grid, when the number of cells in the grid is filled

The event was triggered when

Onenddrag triggers the event when the user stops dragging the grid

OnEnter The event is triggered when the grid has the focus

OnExit The event is triggered when the grid loses focus

OnKeyDown when a user presses any key or key combination in the grid, the event is triggered

OnKeyPress when a user presses any number key or letter key in the grid, it touches

Send the event

OnKeyUp triggers the event when the user releases any pressed keys in the grid

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

These events are useful when we develop real-world applications, where readers can carefully examine the purpose of these events and refer to online Help information.

For example, we could write a handler for the OnDblClick event for the Tdbgrid part, and when the user double-clicks the left mouse button in the grid, a list box pops up for the user to select a field value for a column in the grid. In Example 16.1, we create the application shown in Figure 16.5, set the Visible property of each field part in Object inspector, and display only the Custno, company, Country, and city fields in the grid. We write ondblclick event processing for DBGrid, when the user edits the Country field, double-click the left mouse button to pop up a list box ListBox1, which shows "China", "America", "Japan", "Britain", "France", "Russia" for users to choose from, After the user clicks the country name, the appropriate continent name is selected in the grid.

Where the ListBox1 items property is written to the name of the country, and the Visible property is set to False.

6.5 Tdbnavigator parts and their applications

The tdbnavigator part is primarily used to record navigation in a dataset and to provide a simple set of control buttons for users to manipulate records in a data set. The Tdbnavigator part contains a set of control buttons that the user clicks to move the record pointer backward, insert a record, modify an existing record, change the record of the posting, cancel the modification, delete the record, and refresh the display of the record.

Figure 16.7 is the control button in the Tdbnavigator part.

The following table describes the individual control buttons in the Tdbnavigator part.

Table 16.8 The control button in the Tdbnavigator part

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Button name Main function

─────────────────────────────────

First moves the current record pointer to record one in the database table

Prior move the record pointer to the previous record in the current record

Next moves the record pointer to the next record in the current record

Last moves the current record pointer to the final record in the database table

Insert invokes the Insert method of the dataset part, before the current record

Inserts a new record and sets the dataset part to the Insert State

Delete Deletes the current record if the tdbnavigator part of the Confirmdelete

When the property is set to True, the delete confirmation dialog box pops up

Edit sets the dataset part to edit state so that the user can modify the current record

Post posting changes to the current record

Cancel cancels the modification of the current record and sets the dataset part to browse state

Refresh clears the display buffer of the data-browsing part and uses the data associated with it

The record in the set part (ttable or tquery) refreshes the display buffer.

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Tdbnavigator parts have fewer properties. Here's a simple introduction: An important property of the Tdbnavigator part is the Visiblebuttons property, which contains multiple optional extended child properties, which are mainly used to select the display of each control button in the Tdbnavigator part. Because in the actual application, we do not need so many control buttons. In an application that browses a database table, we typically only need first, Prior, Next, and last four buttons, so we set the other button to false in the Visiblebuttons property.

Showhint Property: This property is a Boolean property that controls whether to display dynamic hints for each button in the Tdbnavigator part. By default, the value of this property is false, and when the value is set to True, when the user pauses the mouse cursor over a control button in the Tdbnavigator part, more than 1 seconds later, Delphi automatically displays a hint about the control button.

Hints property: By default, each control button in the Tdbnavigator part has a corresponding dynamic hint, such as the One, Prior, Next, last, and so on, the user can, depending on their needs, By setting the Hints property, you can set additional dynamic hint information for each control button, and the user's own set of dynamic prompts will overwrite the original message.

16.6 Tdbmemo parts and their applications

The Tdbmemo part is primarily used to display and edit field values for a sophomore (BLOB) type in a database table. The Tdbmemo widget can display multiple lines of text, and allows users to enter and modify multiple lines of text information, which is the only data browsing part of the Delphi text field used to display and edit the sophomore type in the database table.

The main properties and functions of the Tdbmemo components are as follows:

ReadOnly property: This is a Boolean property, and when true, users can only display blob-type text information in the Tdbmemo part, such as Memo fields in Paradox and dBASE database tables. When false, the user can not only display blob text information in the Tdbmemo part but also allow the user to edit the text information in it.

MaxLength Property: This property is an integer property that sets the value of this property to restrict the number of characters that the user enters into the Tdbmemo part. Setting this value to 0 o'clock indicates that there is no limit to the number of characters entered.

ScrollBar property: Describes whether the Tdbmemo part displays scroll bars.

WordWrap property: Describes whether to automatically wrap when entering text information in a Tdbmemo part, when entered to the right boundary.

Alignment property: Describes the alignment of the text information in the Tdbmemo part, with three optional values: Taleftjustify, Tacenter, and tarightjustify. The meanings are left-aligned, centered and right-aligned.

In the process of running, the user will not be able to cut, copy and paste the text information displayed in the Tdbmemo part, in order to have these functions, the user must programmatically call Cuttoclipboard, CopyToClipboard and Pastefromclipboard method respectively to achieve the cut, copy and paste operation.

Autodisplay property: Because the Tdbmemo part contains a large amount of textual information. It takes a lot of time for the application to display information in the process of running, especially when the user moves the record pointer, updating the information displayed in the Tdbmemo part, which slows down the program greatly. For this reason Delphi sets the Autodisplay property for the Tdbmemo part to control whether the memo field in the table is automatically displayed. When Autodisplay is set to False, only the name of the field in its corresponding table is displayed in the Tdbmemo part, and the text information in the field is not displayed, and if the user wants to browse the text information in the field, double-click the inside of the Tdbmemo part with the left mouse button. When the Autodisplay property is set to True, the field values in its corresponding database table are automatically displayed in the Tdbmemo part.

Note here that the maximum number of bytes to display and edit text information in the Tdbmemo part is 32K, and do not exceed this limit during use.

Figure 16.8 shows a tdbmemo display of Memo fields in a database table. This example is in the C:\Delphi\DEMOS\DA subdirectory, and the project name is FASHFACT.DPR.

Display a Memo field with the Tdbmemo part

16.7 Tdbimage parts and their applications

The tdbimage part has many similar properties as the Tdbmemo part, which is used to display and edit the bitmap image fields of a BLOB type in a database table.

Figure 16.8 also uses a tdbimage widget to display a bitmap image from a database table.

By default, the Tdbimage part allows the user to edit the bitmap image, such as cutting or copying the image onto the clipping board or pasting from the Clipboard onto the tdbimage part, and also calling Cuttoclipboard in the program, CopyToClipboard and Pastefromclipboard methods to achieve the cut, copy, paste operation, of course, to do this must ensure that the Tdbimage ReadOnly property value is false.

The tdbimage part also has a Autodisplay property that controls and acts the same as the Autodisplay property of the Tdbmemo part.

16.8 list boxes and combo boxes in the data browsing widget

There are four parts in the data browsing part similar to list boxes and combo boxes in standard parts, which are primarily a series of selectable field values for the user in a database application. Note that these parts can only be used in conjunction with the ttable part, and not with the tquery part.

Table 16.9 list boxes and combo boxes in the data browsing part

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Part name Purpose

──────────────────────────────────

Tdblistbox when the user modifies the value of the field specified in the current record, the part is available to display

A list of field values for the user to select

Tdbcombobox combines a Tdbedit widget with an optional list of field values,

When a user modifies a field in the current record, you can enter it directly from the part

New field, or you can open a Drop-down list box to select one of these options.

Tdblookaplist when the user wants to edit the specified field of the current record in the database table, use the

This part provides multiple options, which are available from the relevant number of other

Read from the library table and provided to the user as a list box

Tdblookupcombo This part combines the functions of tdbedit parts and tdbcombobox parts, using

The user can enter the field value directly into the part, or from the Drop-down list

box to select an option, except that the option in the Drop-down list box is from

Read from other database tables associated with the.

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

16.9 Tdbcombobox Parts

The Tdbcombobox part contains the full functionality of the Tdbedit part, which is similar in that it has a drop-down list box at the same time that the Tdbcombobox part is running, and there is a set of selectable items in the Drop-down list box for the user to choose from. These optional options are provided by the program designer at design time to the Tdbcombobox part's items properties. Figure 16.9 is the contents of the Drop-down list box for the Tdbcombobox part, noting that the Tdbcombobox part must correspond to a field in the database table.

Figure 16.9 Tdbcombobox part in the process of running

An important property of the Tdbcombobox part is the Items property, which contains the options for the Tdbcombobox part in the Drop-down list box when it is run, and the contents of the items can be specified in the design phase.

If a tdbcombobox part corresponds to a field in a database table, when the user wants to edit the value in the field, you can open a Drop-down list box from which to select an option as the field value, or you can enter one of the other field values in the Tdbcombobox part.

The Tdbcombobox component also has some of the following important properties, mainly used to control the display mode and style of Tdbcombobox parts.

Style Property: Controls the display format of the Tdbcombobox part list box when its value is:

Csdropdown

By default for this value, a drop-down list box and an edit box are displayed, and the options in the Drop-down list box are strings and the height of each selection occupies.

Cssimple

Only one list box is displayed, and the options in the list box are strings, and each option occupies the same height.

Csdropdownlist

Displays a Drop-down list box and an edit box, but the user cannot enter a value in the edit box that is not in the list box.

Csownerdrawfixed and Csownerdrawvariable

See the online Help for more information about not only string options in a list box but also other types of options, such as bitmap images.

Dropdowncount property: Allows the maximum number of options to be displayed in a list box, and when the number of options is greater than the value of the property, the user can view all of the options with the scroll bar, and when the number of options is less than the property value, the list box automatically resizes to show all the options.

ItemHeight Property: Use this property to set the height of each option in a list box when the style property of the Tdbcombobox part is set to csownerdrawfixed.

Sorted Property: A Boolean property that determines whether an option in a list box is sorted alphabetically.

16.10 Tdblistbox Parts

The basic functions of the tdblistbox part are essentially the same as the Tdbcombobox parts, except that the Tdblistbox part does not have a drop-down list box but a list box that displays a set of options for the user to select in the list box, and in the process of running, The user clicks the option to assign a field value to the field corresponding to the Tdblistbox part, but the user cannot enter a field value from the keyboard that does not exist in the list box.

If you tdblistbox a specific field in the database table in your application, when you move the record pointer in the dataset, the value of the field corresponding to the Tdblistbox part in the current record is displayed in the Tdblistbox Part's list box with a high brightness, If the field value for the current record is not in the list box, none of the options in the list box are displayed in a high brightness.

Several properties of Tdblistbox:

IntegralHeight Property: This property is used to control the display format of a list box in a tdblistbox part. When this property value is True (this value is by default), the options at the bottom of the list box are automatically moved to the top of the previous selected option. When the value of this property is False, the display of the options at the bottom of the list box depends on the ItemHeight property of the Tdblistbox part, and the options at the bottom of the list box may not be fully displayed.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.