Delphi7 database programming-tdataset

Source: Internet
Author: User

The tdataset class consists of tbdedataset (BDE component), tcustomadodataset (ADO component), tibcustomdataset (Interbase component), tcustomsqldataset (dbexpress component), and tcustomclientdataset subclass.

The following describes the important attributes of the dataset class (there may be trade-offs, which will be supplemented when the project is actually used)

1. Active: determines whether the database has been opened;

2. bof: determines whether the first record of the dataset is activated (and is true in the following states: 1. open a dataset. 2. use the first method to access the dataset. 3. the prior method is used and the method is invalid. 4. setrange method for setting an empty range or dataset );

3. Bookmark: Set a bookmark in dataset;

4. buffers: Provides indexes in the internal cache to access the Record Buffer;

5. currentrecord: Index of the current record in the internal cache of the record cache;

6. datasource: data sources of other datasets with provided values. The default value is nil;

7. EOF: determines whether the dataset points to the last record (true in the following status: 1. open an empty dataset. 2. call the last method. 3. call the next method, but the current record is already the last record; 4. call the setrange Method for null range or record );

8. Found: whether the data is successfully moved to a different record;

9. isunidirectional: determines whether the dataset is a subset of tcustomsqldataset;

10. modifid: Can the activity record be modified;

11. recno: Number of active records returned in a dataset;

12. recordcount: number of records associated with the dataset;

13. recordsize: indicates the size of the internal buffer (in tdataset, recordsize is 0 );

14. state: Set the status of the current dataset operation mode (when a dataset is opened, the status changes from dslnactive to dsbrowse; Edit status (dsedit); insert status (dsinsert ); call setkey or setrange (dssetkey); posting or canceling (changed from current status to dsbrowse); closing dataset (changed from current status to dslnactive ));

15. fieldvalue: provides access to the values of all fields in the activity records of the dataset. (Important)

 

The following describes the important methods in the tdataset class:

1. activebuffer: returns a pointer to the activity record cache. (Often works with bookmark to record the bookmark information in the cache of activity records)

2. append: Add a new and empty record to the end of the dataset. (Important)

2.1 appendrecord: Add a new and empty record to the end of the dataset and automatically post the record. For example

Customer.AppendRecord([CustNoEdit.Text,CoNameEdit.Text, AddrEdit.Text, Null, Null, Null, Null, Null, Null, DiscountEdit.Text]);

 

3. fieldbyname: access by field name (only used to access existing fields; otherwise, an edatabaseerror error is reported ). (Important)

4. Post: Write the modified records to the database or log [the ADO component directly submits the data to the database server]. (Important)

Procedure tform1.button1click (Sender: tobject); begin sampletable. append; // Add a new record sampletable. fieldvalues ['alpha']: = edit1.text; // set two fields and assign values to sampletable. fieldvalues ['integer']: = strtoint (edit2.text); sampletable. post; // submit the record to the database or log end;

 

5. Cancel: if the activity record does not have a post, the activity record can be canceled. However, if the record status is not (dsedit or dsinsert), the method is invalid. (Important)

6. clearfields: clears the values of all fields in the activity record.

7. Close: close a dataset. (Important)

8. Create: Create a tdataset object. (Important)

9. Delete: delete an activity record and move the pointer to the next record of the DataSet object. (Important)

10. destory: destroys a DataSet object (in general, dataset is automatically recycled ). (Important)

11.1 disablecontrols: displays the disabled data associated with a DataSet object using the Data Control.

11.2 enablecontrols: opposite to disablecontrol.

12. Edit: the DataSet object enters the editing state. (Important)

13. findfield: Search for the specified dataset field. (If not found, Nil is returned.) (important) for example:

with Table1 dobegin  FindField('CustNo').AsString := '1234';  Fields[0].AsString := '1234';end;

 

14.1 findfirst: whether to specify the first record of the DataSet object. The bool type is returned. (Important)

14.2 findlast: opposite to the findfirst method. (Important)

14.3 findnext: determines whether the pointer locates the next data record of the DataSet object and returns the bool type. (Important)
14.4 findpior: opposite to the findnext method. (Important)
If false is returned, the activity record is successfully modified. If true is returned, the modification is successful.

15. First: The first record to be moved to dataset. This method is called to set the first record of dataset to active. (Important)

16. 1 bookmarkvid: specifying the validity of a bookmarkd.

16.2 comparebookmarks: Use the virtual method to compare two bookmarks. (If bookmark1> bookmark2, comparebookmarks (bookmark1, bookmark2)> 0)

16.3 getbookmark: assigns tags to activity records of a dataset. (Obtained by tbookmark)

16.4 setbookmark: Set a tag for the activity record of the dataset.

16.5 gotobookmark: The position marked by a bookmarked dataset activity record. (Important)

16.6 freebookmark: Release the memory allocated to the specified tag. (Important) for example:

Procedure tform1.copydataclick (Sender: tobject); var saveplace: tbookmark; prevvalue: variant; begin with mydata do begin {Get a bookmark so that we can return to the same record} saveplace: = getbookmark; // get a tag try {move to prior record} findprior; {get the value} prevvalue: = Fields [0]. value; {move back to the bookmark this may not be the next record anymore if something else is changing the dataset asynchronously} gotobookmark (saveplace); {set the value} fields [0]. value: = prevvalue; {free the bookmark} finally freebookmark (saveplace); end;

 

17. getcurrentrecord: records returned in the cache. (If false is returned, it indicates that the cache area fails to be filled. If true is returned, the cache is successful.) (important)
18. getdetaildatasets: fill a dataset that is not nested into a dataset list.

19. getfileddata: retrieves the value of the current field in the cache. (Return bool value. If false is returned, the value is not extracted successfully)

20.1 insert: Insert a new and empty record into the dataset. (Important)

20.2 insertrecord: Insert a new, empty record into the dataset and post it automatically. (Important)

21. isempty: determines whether the dataset is empty. (Important)

22. islinkedto: determines whether the dataset is connected through datasource. (Important)

23. Last: Move the pointer to the last record of the dataset. (Important)

24. moveBy: move from one activity record to another. (Important)

25. Next: Move to the next record. (Important)

procedure TForm1.Button1Click(Sender: TObject);var  i: Integer;begin  with ProgressBar1 do  begin    Min := 0;    Max := Customers.RecordCount;    Customers.First;    for i := Min to Max do    begin      Position := i;      Customers.Next;    end;  end;end;

26. Open: Open the dataset. (Important)

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.