15th chapter-Application and programming of data access Parts (II.) (1)

Source: Internet
Author: User

The dataset part ttable or Tquery has many events. Writing the appropriate program code for these events can validate, compute the value of a computed field, confirm multiple operations on a database table, and so on. These events and their descriptions are shown in table 15.4.

Table 15.4 commonly used events for dataset parts

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

Event description

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

Beforeopen,afteropen is triggered before/after the dataset part is opened

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

Beforeclose,afterclose is triggered before/after the dataset part is closed

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

Beforeinsert,afterinsert is triggered before/after the dataset part enters the insert state

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

Beforeedit,afteredit is triggered before/after the dataset part is edited

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

Beforepost,afterpost is triggered before/after the data set is posted to a modified record

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

Beforecancel,aftercancel is triggered before/after the dataset part cancels the previous step

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

Beforedelete,afterdelete is triggered before/after the dataset part deletes the current record

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

Onnewrecord is triggered when a new record is created

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

Oncalcfields is triggered when a field value is calculated for a calculated field in a table

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

15.4 Ttable Parts and applications

In the previous section we introduced some common properties and methods of the DataSet widget Ttable and Tquery. The ttable part is one of the most important parts to be used frequently in the Delphi database programming, it is one of the dataset parts that the database application must use when accessing the database, in this section, we focus on the properties and methods peculiar to the ttable part, ttable all the properties of the part, Methods and events can be found in the online Help.

Main properties of 15.4.1 Ttabel parts

DatabaseName Properties and TableName properties:

The DatabaseName property is the name of the database that describes the database application, which can be the alias of the database defined by BDE, the disk path where the explicitly stated database file resides, or a database name defined by the tdatabase part. The DatabaseName property is often an alias to a database defined by BDE. The advantage of using the alias of the database defined by BDE instead of the actual path and name of the database is that when the actual database is stored in a different location, simply use the BDE to simply set the alias of the database, and the database application needs no modification. Refer to the BDE Settings application for the use of BDE. The Tabelname property is used to describe the actual database table that the current ttable part is connected to. These two properties are typically specified at design time, but can also be set while the program is running, but to modify both properties, you must do so when the Ttabel active property is false, and when the active property of Ttable is true, These two properties cannot be modified and set.

Tabletype Properties:

This property describes the type of database table that is connected to the ttable part. When the Tabletype property is set to default, the type of database table described by this property is determined by the extension of the database file.

If the database file has an extension of. db or no extension, table type is Paradox table

If the database file has an extension of. DBF, the type of table is dBASE table

If the database file has an extension of. TXT, the type of table is an ASCII table

If the Tabletype property is not set to default, the type of the database table that is connected to the ttable part is determined by the value of the setting in Tabletype, regardless of the extension of the database file.

Keyexclusive Properties:

One of the effects of this property is to show whether the record is moved to a record that matches the lookup value or moves the record pointer to a record that matches the lookup value when the record is found in the database table. This property is a Boolean variable that moves the record pointer to the next record in the matching record when its value is False (by default, false), moves the record pointer to a matching record, and true. Another effect of this property is to specify whether to include boundary records that satisfy the filter criteria when the search scope is specified in the table. When the value of Keyexclusive is false, the search scope includes boundary records, otherwise the boundary record is not included, see "Qualifying the search scope for records in a table" for detailed operations.

Indexfields Properties and Indexfieldscount properties:

The Indexfields property value is the list of field names in the database table that contains all the index letters in the database table that is connected to the ttable part. The Indexfieldscount property describes the number of indexed fields in the table. Both of these property values are read-only and are available only if the program is running.

IndexName Properties and Indexfieldnames properties:

The IndexName property holds all the secondary index names defined for the database table when the database table is established, which is a list of secondary index names and is a read-only property. The Indexfieldnames property specifies the name of the field used for the sorting of the database table indexes, separated by semicolons. For example, you can set indexfieldnames values for customer records in the Customer.db table by postal code ZipCode and customer number Custno:

ZipCode; Custno

The field specified in the Indexfieldnames property must exist in the corresponding database table, or it can cause an error. IndexName and Indexfieldname are mutually exclusive, specifying the value of one of the properties at a time, and cannot specify property values for two properties at a time.

Exclusive properties:

This property is a Boolean property that indicates whether the database table is opened in a shared way, and if the value of exclusive is true, other users cannot access the table when a database table is opened, and if the value of exclusive is false, a database table will be opened as shared. It is obvious that you cannot open a table that other users are accessing in a mutually exclusive manner (set exclusive value to True). For a database table on a SQL database server, when opened by a user in a mutually exclusive manner, other users can read the data in that table, but not the data in the table, although some database servers do not support this approach, as detailed in the documentation for the database server.

ReadOnly Properties and Canmodify properties:

Both properties are Boolean, and the ReadOnly property determines whether the user can read or write data in the table. When ReadOnly is true, the user can only read data from the table, and when ReadOnly is False, the user is able to read and write data from the table (assuming that the database has been authorized to read and write to the database table). The Canmodify property is a read-only property, and the user cannot modify its property value, which reflects the actual privileges that the user has on the database table, and when ReadOnly is True canmodify automatically is set to False, and when ReadOnly is false, Canmodify is true if the database allows users to read and write to a table, otherwise canmodify is false. When Canmodify is false, the database table is read-only, but cannot be placed in an edit or insert state; When the Canmodify property is true, the dataset part of the database table can be placed in an edit and insert state. However, this does not mean that users can insert and modify data in the table, as this is subject to other constraints, such as user access to the SQL database server.

Ttable parts also have some other properties see online Help

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.