ClientDataSet small knot

xiaoxiao2021-03-06  53

Usually in the database program design, you will have a good data set connection, then use the data set component (from TDBDataSet class inheritance) to obtain the data in the database, and through the data set element in the buffer to make a variety of operations.

In fact, it can be understood that after obtaining information from the database, the data set is placed into a buffer in a buffer, while the content displayed in the program is the content of the buffer. There is a indicator pointing to the current record in the buffer. Then we operate on the data by operating the indicator, and finally, the data set will be stored to the database.

The data set components have many identical properties and methods, which is also what we are encountered in our usual design, let's go, let's take a look:

Attributes

(1 )ActiveActive property is a Boolean type variable, used to specify whether the data set element is open, it is obvious that the property is TRUE! You can assign an Active to the Active or call the OPEN method or a Close method.

(2) BOF, EOFBOF and EOF reflect the position of the current indicator record, and is the Boolean type. When BOF is True, the indicator points to the first record; EOF is TRUE, indicator points to the last record. When you open a data set, the default is to point to the first record, both Bof is True. If there is no record in the data set, Bof and EOF are TRUE.

CA2red, FilterOptions, Filter These 3 attributes are generally used to filter. Filtered is a Boolean type variable that performs the settings in the filter condition when the data is read when assigning TRUE. FilterOptions determines how to use the screen detection, it has two options: FocaseInSensitive (Sensitive is sensitive), FonopArtiaLCompare (whether support wildcard *). Filter determines the conditions of filtering, a string variable, string, such as: field name operation value value. For example: "ID <100" is a record that only the ID field is less than 100. This property can be set when running or design.

⑷fields, Fieldcount See the definition of Fields in Help: Property Fields: Tfields Hey, we can learn that it is a TFIELDS object. Through the fields attribute, we can directly access a certain field of the current indicator record, which means that we can access the fields attribute as an array, get information (in BCB) through the Fields [serial number] .sstring. Fields [serial number] -> asstring, the serial number starts from 0, until FieldCount-1, a total of FieldCount information. The FieldCount property indicates how many fields are currently recorded. For example: edit1.text: = custtable.fields.fields [0] .sstring; (for edit1-> text = customle.fields-> infway; )-> asstring;

⑸fielddefs, open help: Property Fielddefs: tfielddefs; we know from HELP, you can access and set information type, data length, etc., information length, etc. .

⑹fieldvaluesfieldvalues ​​is a variable variable of a Variant type, or you can access each field value of the current record like Fields. Help is defined as follows: Property FieldVale: String]: Variant; default; This property is the value of the column value by the column name, can modify and access the field, and the field name is specified in the fieldname. Do not distinguish between case. Since it is Variant, you can represent all types of information, pay attention to assign a value for this attribute, the data type and the data type defined by the field is consistent! ⑺recnorecno is an Integer type variable. Through the RecNo property, you can know that the current indicator points to the sum of the data sets, or modifies the RecNo to enable the indicator to jump to the desired record. Since RECNO is a long-integer variable, its value should be between 1 to record total. If the value assigned to Recno is outside this range, the indicator will not move.

⑻RecordCountRecordcount is a only-read Integer variable, through which we can get the total number of records of the current data set.

The ⑼StateState property is used to illustrate the status of the current data set. By determining whether to perform index operations by judging State.

⑽CacheDUPDates This property specifies whether the data set supports the information list update operation cache, TRUE is a support. Such benefits are the contents of the current data concentration and not immediately update the database, reduce the number of database transactions and network traffic.

The currently used attribute is above, let us take a look at the method of sharing information.

(1) Append method is to allow the data set to enter a new recorded state. This record is an empty record, and the current indicator will also point to the empty record, and then enter the information. Note, this record is only existing in the data set, and does not add to the database. If you want to add it to the table, you want to call the POST method.

(2) Look at the original shape in HELP: Procedure appendrecord (const value is used); this method is used to add a new record. Please note that it is distinguished from (1) disc: AppendRecord uses the information in the new record as a parameter. This saves the steps to assign values ​​after calling the Append method.

(3) Cancel, PostCancel is used to cancel the new, editing, etc. to modify the data set. POST is to store new, editing, etc. from the data set into the database.

⑷clearfields uses this method to clear all the field contents in the recorded record.

⑸Open, Close opens and closes the connection of the data set, and the Acitve property will change.

⑹EDIT This method is to make the data set into the editing state, and edited is the current state. Note that if you have an editing, it is not an editable state, an exception is triggered. Then you need to use the Edit method to enter the editing state. (This sentence seems to be equal to not saying it)

⑺applyupdates, Cancelupdates, CommitUpdates, RevertRecord These 4 have a common: put the operations of the information in cache, in the end, stored in the database, and support the cancellation of the database operation. ★ ApplyUpdates: Yes Add the operation of the data set to the operation buffer, not in the database! Calling this method You can check if this operation is in line with the rules of the database, and if the operation is not legal, it will trigger an exception. At this point, the ROLLBACK method available in the database can be undone or withdraw the operation via Cancelupdates. ★ Cancelupdates: Undo the update in cache ★ commitupdates: Store all updates in cache to the database, this operation is the ultimate, can not recover, please pay attention! ★ REVERTRECORD: Undo the operation just recorded for the current record. When using 4 methods above, the cachedupdates property must be true. ⑻FETCHALL This method is used to solve the transfer of secretary traffic between the remote database. In fact, it first stores the operation of the database update in the buffer to the database, and then obtain the current record of the last record from the database, 嘿嘿, this is not to reduce the traffic of the Internet!

⑼fieldbyname Use this method through the field name to access the information set. The current record is currently recorded. This method is similar to the FieldVALUES attribute. However, FieldbyName can only be used to get the value of the field and cannot assign a value, and FieldByname returns a TField object, in addition to the value, there is a field information .. This method uses frequent frequent frequent, from the posts in the station.

Four methods of ⑽findfirst, findnext, findprior, Findlast are used to find records that meet the filtering rules. ★ FindFirst: Find the first rule record ★ FindNext: Find the next rule record starting from the current record ★ Findprior: Find the last rule record starting from the current record ★ Findlast: Find the last rule recording

The four methods of ⑾first, next, prior, and last are used to move the indicator of the recorded pointing record. ★ first: Move the indicator to the first indicator ★ Next: Move the indicator from the current record to the next record ★ PRIOR: Move the indicator from the current record to the previous record ★ Last: Move the indicator to the last record

⑿lookup This method is used to retrieve records that meet certain conditions. If you know the recorded record, return the value of the specified field. This method has 3 parameters: ★ Keyfields: The field used to specify the search, can be one or more field names, separated by separation by separation. ★ KeyValues: Since the type is a Variant type, you can include any information type. It specifies the value of the search field to match. If you want to specify multiple search fields, then the keyValues ​​parameter needs to generate a Variant type array with the VarrarrayOf function ★ Resultfields : When you find a record, the returned field is specified by this parameter, which is also possible to be one or more fields. Pay attention, this parameter is also a Variant type!

⒀locate is similar to the above ⑿lookup method, and is also a record used to search for specified conditions. Different places are that Locate does not return any values, but only the indicator moves to the eligible record, and Lookup does not move the indicator. The parameter keyfields parameters in LOCATE are the same as the meaning of KeyValues ​​parameter in lookup. It is important to note that Options is a collection that specifies the way to find. It includes two options: LocaseInSensitive and loPartialKey. The former is not sensitive to case; the latter is partially matched. ⒁ Insert, INSERTRECORD These 2 methods are used to insert a record before the current record. Similar to the method such as (1), the Insert method allows the information set to insert a recorded state, add an empty record in the data set, the current record indicator also points to this empty record, the user can record this record Enter the value. This record is only existing in the data set. If you want to add to the database, you will use the Post method. The INSERTRECORD method is the data directly in the new record as a parameter. This saves it to assign a value after calling the insert method.

⒂Moveby is used to move the metrics in the data set, and set the RecNo property. However, Moveby is relatively moved, and Recno is absolutely moving.

⒃Refresh This method will re-acquire data from the database and refresh the data set, and will keep the position of the previous indicator, but it is not guaranteed to be completely unchanged, because it is possible that the record has been deleted after being refreshed.

⒄Setfields This method makes the data set in an edit state, which can add data from all fields to the current record at one time.

Use the red key to search in the station, you can get more detailed usage, I will no longer draw the snake!

转载请注明原文地址:https://www.9cbs.com/read-57443.html

New Post(0)