15th chapter-Application and programming of data access parts (i) (4)

Source: Internet
Author: User

Setrecords Method: Call this method to modify the values of multiple fields of the current record in the table, before calling the method, you must place the dataset part in the edit state, and after calling the method, call the Post method to actually write the current record's modification back to the database table. When the Setrecord method is invoked, the modified field value must correspond to the field name that actually exists in the table, and the data type should match. For example, the following code modifies the record just inserted above.

Table1.edit;

Tabel1.setrecord (,,, 9600000,1200000000);

Tabel1.post;

This section of code modifies the value of the area and population fields of the record that you just inserted, and there are no modifications to the Name,continent and Captial fields.

In the dataset part, there is also an important way to abort methods, which are used to cancel calls from other methods, such as requiring the user to confirm that the action is actually performed before inserting a record, modifying a record, or deleting a record, and then invoking the Abort method to cancel the invocation of various methods. The following code is to let the user confirm that the deletion is actually performed before the user deletes a record.

Tabel1.beforedelete (Dataset:tdataset);

If Messagedlg (' Really want to delete records? '),

mtconfirmation,mbyesnocanel,0 <> Mryes Then

Abort; {Cancel delete operation}

About bookmarks (bookmark) operation;

Bookmarks are used primarily to quickly position the record pointer in a table, where the record pointer is often saved in the application, and after other processing, you want to quickly return to where the previous pointer is located, which is especially useful when using bookmarks. For the bookmark operation, Delphi provides three methods, which are:

GetBookmark

Gotobookmark

Freebokmark

These three methods are generally used together, and the GetBookmark method returns a Tbookmark type variable that contains a pointer to the current record, which is used to quickly position the record pointer to the record where the bookmark is located. The Freebookmark method is the opposite of the GetBookmark method, which frees the bookmark flags. The following program code illustrates the general method of bookmark manipulation:

Bookmark:tbookmark;

<do something>

BookMark: = Table1.getbookmark; {Bookmarks The current record as a marker}

Table1.disalbecontrols; {Disconnect Table1 from data-aware parts}

Table.first

While don't EOF do {Other processing of all records in a table}

Begin

<do something>

Tabel1.next;

End

Tabel1.gotobookmark (BookMark)

Table1.enablecontrols; {Reposition The record pointer back to its original location}

Tabel1.freebookmark (BookMark); {Remove Bookmarks Bookmark flag}

15.3.5 the connection between the dataset part and the data browsing part

DataSet Parts Ttabel and Tquery have three methods, the Disablecontrols method, Enablecontrols method, and Refresh method are used to control the connection between the dataset part and the data browsing part associated with it, and to control the display of the data browsing part. Calling the Disablecontrols method is important when the user modifies and updates and traverses records in a database table, calling the Disbalecontrols method to sever the connection between the ttable or Tquery part and the data browsing part, so that the data browsing part is temporarily invalidated, otherwise , after each modification of the ttable or tquery part, all the data-browsing parts of the form that are attached to them update their display, which obviously slows down the processing. When you traverse a record in a table, each time the record pointer moves, the data browsing widget in the form updates the display and flashes on the screen.

The effect of the Enablecontrols method is the opposite of the Disbalecontrols method, which calls the Enablecontrols method, which restores the connection of the ttable or tquery parts to the data browsing part. Restores the temporarily defunct data browsing widget to the state of recording information in the normal display table.

The Refresh method refreshes the display in the data browsing part. When you call the Refresh method, you must make sure that the ttable or Tquery part is open. When a record in a dataset is modified, the Refresh method is invoked, and the information displayed in the data-browsing part changes.

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.