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

Source: Internet
Author: User
Tags empty

Method and application of 15.4.2 ttable parts

15.4.2.1 set the scope of use of database tables

In our actual application of the database table is often a large number of data information, which contains a lot of records, and our application may only need to operate on one part of the records, so it is particularly important to specify a scope of use for the application, To easily and efficiently specify the scope of use of database tables Delphi provides the following methods for ttable parts for users to use:

Setrangestart and Editrangestart methods

Setrangeend and Editrangeend methods

SetRange ([Start values],[end Values]) method

Applyrange method

Cancelrange method

1. Setrangestart method

Used to specify the starting record for the search scope, after calling the Setrangestart method, you can specify the corresponding field values for one or more fields of the start record. The Setrangeend method specifies the end record of the retrieved range, and after calling the Setrangeend method, you can specify the corresponding field values for one or more fields of the end record.

2. SetRange method

The SetRange method contains the functionality of the Setrangestart and Setrangeend methods that specify both the start and end records of the retrieval range, and the field values of the start and end records are sent to the SetRange as an array, in the form of:

SetRange ([Start value],[end value])

3. Applyrange method

Depending on the start and end records of the search scope of the Setrangestart,setrangeend or SetRange method description, a search scope is specified, and after the Applyrange method is invoked, the application can only perform operations on the records within the retrieved scope.

 

4. Cancelrange method

The effect of the Cancelrange method is the opposite of the Applyrange method, which is to cancel the retrieval range set for the table, after invoking the Cancelrange method, the application can perform the operation on all records in the table.

Notice here that if we are using a Paradox table or a dBASE table, when we invoke the Setrangestart,setrangeend and the SetRange method, we can only specify the corresponding field values for the indexed field or the defined index in the table to set the search scope. If you use a database table from a SQL database server, you can specify the corresponding field value for the field specified in the Indexfieldnames property.

For example, suppose Table1 is connected to a customer.db table, customer.db one of the indexed fields is Custno, and there are two edit boxes Startval and endval in the form to enter the values for the field Custno for the start and End Records. The following program code allows us to set a search scope:

Tabel1.setrangestart; {Specify the starting record for the range to retrieve}

tabel1custno.asstring:= startval.text {Specify field value for the Custno field of the starting record}

Tabel1.setrangeend; {Specify the end record for the retrieved range}

If Endval.text <> ' then

Tabel1custno.asstring: = Endval.text; {Specify field value for Custno field of end record}

Tabel1.applyrange; {To set the retrieval scope based on the start of the search range and End Records}

Note that the above program code, when specifying the field value for the Custno field of the end record, first checks to see if the value of the Endval is empty, and if the Endval value is empty, the set retrieval range does not contain a record because the field value for no record is less than the nil If the value of Startval is empty, the retrieval scope begins with the first record in the table because the field value of any record in the table is greater than empty (NIL).

The above code can be rewritten with the SetRange method:

If endval.text <> ' Then

Tabel1.setrane ([startval.text].[ Endval.text]);

Table1.applyrange;

The use of Editrangestart and Editrangeend methods is exactly analogous to the Setrangestart and Setrangeend methods, except that the two methods are to set an editable range.

For example, suppose that an index in a table contains two fields LastName and FirstName, we specify the corresponding field values for one or more fields in the index, and set the scope of use of the database table.

Table1.setrangestart;

Table1.fieldbyname (' LastName '). Asstring: = ' Smith ';

Table1.setrangeend;

Tabel1.applyrange;

The above code sets the scope to include all records with the value of the LastName field greater than or equal to Smith. The following code sets the range to include records with the value of the LastName field greater than or equal to Smith and the value of the FirstName field is greater than or equal to ' J '.

Table1.setrangestart;

Table1.fieldbyname (' LastName '). Asstring: = ' Smith ';

Table1.fieldbyname (' FirstName '). Asstring: = ' J ';

Table1.setrangeend;

Tabel1.applyrange;

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.