Chapter 6 What is the four types of standard data set components in Delphi 4, which are TTable, TQuery, TstoredProc and TclientDataSet. These data sets are inherited from a common base class TDataSet, where only TclientDataSet is inherited directly from TDataSet, while TTABLE, TQUERY, TSTOREDPROC's direct superior is TDBDataSet, TDBDataSet's superior is TBDedataset, TBDedataset's superior It is TDataSet. The inheritance relationship between these classes can be represented by Figure 6.1. Figure 6.1 Inheritance relationship of data sets TDataSet is an abstract base class for all data sets, and most of its properties and methods are virtual or abstract. The so-called virtual method refers to these methods can be derived overloaded. The so-called abstract method refers to these methods only declares, no definitions, derived classes must be defined before they can call these methods, and different derived classes can have different definitions. Due to the Abstract method in the TDataSet, you cannot create its instance directly, otherwise it will cause an error error. If you are functioning, TDataSet's properties and methods can be divided into such blocks: open and close dataset, browse, edit data, bookmark management, control connection, access field, recording buffer management, filtering, and events. 6.1 Opening and Closing Dataset Before making any action on the dataset, first open the data set. To open the dataset, you can set the Active property to true, for example: custTable.active: = true; Open function can also be called, for example: CustQuery.Open; To turn off the dataset, you can set the Active property to false or call the Close function. . 6.2 Status of the status dataset of the dataset (state attribute) determines the operation that is currently able to perform the data set, for example, when the data set is closed, its status is DSINACTIVE, which is not accessible to any data of the data set. 6.2.1 State Properties The state attribute is read-only. The following list is listed below: .dsinActive Dataset has been turned off, you cannot access its data ;.dsbrowse dataset is open, you can browse data but cannot modify data; .dsedit At this time, you can modify the data; .dsInsert can be inserted into a new record at this point ;.dssetkey only applies to TTable and TclientDataSet, at which time you can set the range and key value, and you can call the gotoKey function; .dscalcfields is being Process the oncalcfields event, the value of the non-calculated field cannot be modified; .dsCurValue is used inside; .dsNewValue internal use; .dsoldValue internal use ;.dsfilter is performing filtering operation. When a data set is just open, its State property is set to DSBROWSE, and the value of the State property will automatically change with the application of the application. To enable the data set to DSBROWSE, DSEDIT, DSISERT, or DSSetKey status, you have to call the appropriate method.
For example, to enter data set CustTable dsInsert state, the following exemplary procedure: Procedure TForm1.InsertButtonClick (Sender: TObject); BeginCustTable.Insert; {enters state dsInsert} AddressPromptDialog.ShowModal; If AddressPromptDialog.ModalResult: = mrOK thenCustTable.Post; { Restore to DSBROWSE status} elseCustTable.cancel; {Restore to DSBROWSE status} END; From the above example, some operations will automatically turn the dataset to DSBROWSE status, for example, if the POST function is successful, the data set is restored. For the dsbrowse state, if the call post is not successful, the data set still maintains the original state. Calling Cancel also enables the dataset to recover to the DSBROWSE state. If you set the Active property to false, or call the Close, the dataset will enter the DSINACTIVE state. For example, the following two lines of code are equivalent: custTable.active: = false; customle.close; Some status If DSCalcFields, DSCurValue, DsNewValue, DSoldValue, and DSFilter cannot be controlled by the application, but by the data set itself automatically Set. For example, when processing the oncalcfields event, automatically enter the DSCalcFields status. When exiting the handle of the ONCALCFIELDS event, the data set automatically restores the original state. When the status of the dataset changes, the onStateChange event of the TDataSource component is triggered. If the DataSet property of this TDataSource component specifies this data set. The following details of the data set will be described in detail and how to enter these states. 6.2.2 DSINACTIVE Status When the data set is closed, it is in a DSINACTIVE state. At this point, any data cannot be accessed. To make the data set into the DSINACTIVE state, you can set the Active property to false, or call the Close. The BeforeClose event is triggered before the dataset will be turned off. When the data set is just turned off, an AfterClose event will be triggered. If the CLOSE is called when the data set is in a dsedit or DSInsert state, it should be prompted to be approved or canceled in the handle of the BeforeClose event. Program example follows: Procedure CustTable.VerifyBeforeClose (DataSet: TDataSet) BeginIf (CustTable.State = dsEdit) or (CustTable.State = dsInsert) thenBeginIf MessageDlg ( 'recognition of changes to do?', MtConfirmation, mbYesNo, 0) = mrYes thenCustTable.Post ElsecustTable.cancel; End; End; 6.2.3 DSBROWSE Status When a data set is just open, the data set is always in the DSBROWSE state. At this time, records in the data set can be displayed, but records cannot be edited and inserted. The DSBROWSE state can be considered to be the basic state of the dataset, in which a state can be entered.
For example, calling the Insert or an Append function will turn the status of the dataset from dsbrowse into dsinsert (of course, this also depends on other factors, such as the value of the CANMODIFY property), calling setKey will make the data set from dsbrowse to DSSetKey state. TDataSet has two ways to return the dataset to the DSBROWSE state, one is Cancel, which will cancel the currently ongoing editing, insert, search, etc., so that the dataset is returned to the DSBROWSE state. The other is POST, which will try to save the modified data to the data set. If it is successful, the data set will return to the DSBROWSE state. If it is not successful, the data set remains the original state. 6.2.4 Dsedit Status If the application wants to modify the data of the data set, you must first enter the Dsedit state. To enter the Dsedit state, you can call Edit. However, calling Edit does not guarantee that you can enter the Dsedit state, which also depends on the value of the canmodify property. If this property returns true, it means that the dataset is readable and written. For TTable components, if the readOnly property is set to true, the canmodify property will definitely return false. For the TQuery component, if the RequestLive property is set to false, the canmodify attribute will definitely return False. Even if the data set enters the dsedit state, it does not mean that the user must modify the data, the readOrthly property of the data control must be set to false. In addition, for SQL databases, users can modify data depends on whether the user has no data to modify data. To return from the DSEDIT status, you can call the Cancel, POST or DELETE functions, where POST and DELETE are not called successful, will still keep the dsedit status. In the data control, when the user modifies the data, the input focus is removed, it is equivalent to calling the POST function, which will cause the dataset to return to the DSBROWSE state. 6.2.5 DSINSERT Status If the application is inserted into a new record, you must first enter the DSInsert state. To enter the DSInsert state, you can call the INSERT or APPEND function. However, calling INSERT or APPEND does not guarantee that you can enter the DSInsert state, depending on whether the value of the canmodify property returns True. Even if the data set enters the DSISERT state, it does not mean that the user can insert records, the readOrthly property of the data control must be set to false. In addition, for the SQL database, users can insert records also depend on the privileges that the user has modified data. To return to the DSBROWSE status from the DSInsert state, you can call the Cancel, POST, or DELETE function, where the POST is not called successful, and still keeps the DSInsert state. In the data control, when the user modifies the data, the input focus is removed, it is equivalent to calling the POST, which will cause the dataset to return to the DSBROWSE state. 6.2.6 DSSetKey Status You can call Locate, and lookup searches for specific records in the data set. For TTable components, you can also call GotoKey, GotoneareAarest, FindKey or Findnearest to search for specific records in the table. Before calling the above method, you must first make the data set into the DSSetKey state. To make the data set into the DSSetKey status, you can call SetKey. After calling the above method, the data set returns to the DSBROWSE state. In addition, the data set can be filtered.
For TTable components, you can set the range in advance. Before the filtering and range operation, you must first enter the DSSetKey status. 6.2.7 DSCalcFields Status When the oncalcfields event is triggered, the data set will enter the DSCalcFields status. In handle the handle of the ONCALCFIELDS event, the value of the "calculation field" should be given. In the DSCalcFields state, in addition to the "calculation field", the application cannot modify the value of other fields, because if the value of other fields changes, the oncalcfields event will be triggered, resulting in an infinite loop. When the oncalcfields event is completed, the data set returns to the DSBROWSE state. 6.2.8 DSFilter Status When the ONFILTERRECORD event is triggered, the data set will enter the DSFilter state. In this state, the record of the data set is not allowed, otherwise, filtering cannot be performed correctly. When the ONFILTERRECORD event is completed, the data set returns to the DSBROWSE state. 6.2.9 DSNewValue, DSOLDVALUE, or DSCurValue When the cached update is allowed, the data set may enter the DSNewValue, DSoldValue, or DSCurValue status when the user modifies the record. In these three states, the value at the time can be accessed by the NEWVALUE, OLDVALUE, or CURVALUE attribute of the field (TField). The above three states are used inside Delphi 4, and the application cannot actively enter the above three states. 6.3 Holding Records Each activity has a pointer, pointing to the current record. Many of the operations of the data set are for the current record, and many data controls only show the current recorded data, so I know that the location of the current record is very important in the database application. Database applications tend to change the current recorded position, this time you need to use these methods: .first makes the first record becomes the current record; .last makes the last record become the current record; .next makes the next record becomes the current Record; .prior makes the previous record become current records; .Moveby makes the record of the current record several rows to the current record. In addition, there is a TDBNAVigator component specifically used to browse records, which is implemented by the above method. In addition to the above method, there are two read-only Boolean properties of the TDataSet to determine the location of the current record, one is BOF, if this property returns True, indicating that the start position of the data set is now available. The other is EOF, if this attribute returns true, indicating that it has now reached the end of the data set. 6.3.1 First and Last Call the FIRST function enables the first record of the dataset to become the current record, and set the BOF attribute to True. If the first record is already currently recorded, the first is nothing. The program example is as follows: customle.first; calling the Last function to make the last record of the dataset becomes the current record and set the EOF attribute to True. If the last record is already the current record, Last is not dry. The program example is as follows: CustTable.last; there are two buttons on the navigator implemented with TDBNAVigator components, respectively, respectively, respectively, respectively. 6.3.2 NEXT and PRIOR Call the next function enable the next record to become the current record. If the current record is already the last record of the dataset, NEXT does not do anything. The program example is as follows: CustTable.next; calling the prior to make the previous record becomes the current record. If the current record is already the first record of the dataset, the prior is nothing.
The program example is as follows: CustTable.Prior; 6.3.3 Moveby calls the Moveby function Make another record in the data set to the current record, which is a few rows from the original current record. Moveby needs to pass a parameter, the number of rows separated, and the positive number indicates the direction in which the recording number is increased, and the negative number is moved to the direction of the recording number. The program example is as follows: customle.moveby (-2); Moveby returns the number of rows that actually move, and the return value is possible to pass to Moveby parameters. Note: In multi-user environments, other users may be modified, inserted or delete records, so that a record is 5 lines from the current record, and now it is possible to become 4 lines and 6 lines, and even the record does not exist. Because other users modify the data of the record or delete the record. 6.3.4 EOF and BOF Attributes TDataSet has two read-only attributes EOF and BOF, which are used to determine if the end of the data set is at the beginning. These two properties are often used when all records of the data set. If the EOF attribute returns true, it is indicated that the end of the data set is now. When the following operations are set to True :. Open an empty dataset; call Last ;. Call next, and now the last record of the data set;. Call setRANGE, scope is invalid of. In addition to the above, the EOF attribute will return false. The EOF property is usually used in a loop, and each call is required to determine the EOF attribute to avoid operation of the absence of records. The program example is as follows: customle.disablecontrols; trycustTable.first; while not customle.eof dobegin ... custom ... custom ... CustTable.Next; End; FinallyCustTable.EnableControls; end; The above code also demonstrates how to temporarily disable data when traversing all records of the data set The control follows. DISABLECONTROLS should be called for disabled before all records traversed in the data set, which can speed up the speed of traversal, because the refresh is also spent. After the traversal is over, you should call EnableControls to recover refresh. EnableControls is best called in the Finally part of the Try ... finally structure, which ensures that the refresh can be recovered even if there is an abnormality in the past. If the BOF attribute returns true, it means that it has now reached the beginning of the data set. When you do the following, you will set the BOF attribute to true :. Open a non-empty dataset; call first ;. Call the PRIOR, and now the first record of the data set. In addition to the above, the BOF attribute will return false. Like the EOF attribute, the BOF attribute is usually used in a loop, and each time the prior is to determine the BOF attribute to avoid operation of the absence of records. The program is now as follows: CustTable.disable.Bof dobewhile not customle.bof dobegin ... custom ... custom ... custTable.Prior; end; finallycusttable.enableControls; end; 6.4 Bookmark bookmarks The role of a mark is a tag in a location in a data set, and can be quickly and convenient Back to that position. Several attributes and methods are provided in TDataSet to manage bookmarks. If you read the Bookmark property, return to the current recorded bookmark. If you write the Bookmark property, it enables a specified bookmark as the current bookmark.
Several functions about the bookmarks in tdataset are virtual, and TDataSet derived TBDASet redefines these methods, including: .bookmarkvalid to determine if a bookmark is legal; .comparebookmarks compares whether the two bookmarks are the same; .getBookmark creates a bookmark Mark the current record; .gotobookmark returns to the location of the GetBookmark mark; .freeBookmark deletes a bookmark. To create a bookmark, first to declare a TBOOKMARK type variable, then call the GetBookmark function to create a bookmark that tag the current record. The TBOOKMARK type variable is actually a non-type pointer. Before calling GotobookMark, it is best to call BookMarkValid to determine if the bookmark is legal, because the bookmark mark records may have been deleted. If BookmarkValid returns true, the manual check is legal, you can call the gotobookmark to jump to the location of the bookmark tag. You can call CompareBookmarks to compare whether the two bookmarks are the same, if the two bookmarks are different, this function returns 1. If both bookmarks are the same or NIL, this function returns 0. GotoBookmark needs to pass a parameter, namely a bookmark. FreeBookmark is used to delete a bookmark. When a bookmark has been used, it should be deleted in time because the bookmark is also a kind of resource. The following code demonstrates the bookmark usage: Procedure DoSomething (const Tbl: TTable) varBookmark: TBookmark; BeginBookmark: = Tbl.GetBookmark; Tbl.DisableControls; TryTbl.First; While not Tbl.EOF DoBegin ... Tbl.Next; End; FinallyTBl.gotobookmark (Bookmark); TBL.EnableControls; TBL.FreeBookmark (Bookmark); End; End; 6.5 Search Specific records You can call Locate and lookup functions to search for specific records in the data set. Locate is used to locate a specific record in the data set and make the record become the current record. Locate needs to pass three parameters, the first is the keyfields parameter, which is used to specify which field search, the second is the keyValues parameter, used to specify the corresponding value of each field, the third is Options parameter, used for setting Search options. The following example searches Company field is "Professional Ltd." record: varLocateSuccess: Boolean; SearchOptions: TLocateOptions; BeginSearchOptions: = [loPartialKey]; LocateSuccess: = CustTable.Locate ( 'Company', '. Professional Ltd', SearchOptions ); END; if locate finds a qualified record, turn the record to the current record and returns True. If LOCATE does not find a matching record, return false. For LOCATE, the more fields specified by the Keyfields parameter, the more accurate the searches. If the keyfields parameter needs to specify a plurality of fields, with a semicolon from each other. Because the data type of the field may vary, KeyValues is a Variant type parameter. If the keyfields parameter specifies a plurality of fields, the KeyVALUES parameter must be an array of variable types.
The program is now, for example, the CustTable Do Locate ('Company; Contact; Phone ", Vararrayof ([' Sight Diver ',' P ']), LOOKUP is very similar to LOCATE, but also searches for specific records in the data set. Different, if a matching record is found, the Lookup returns the value of several fields in the record. Lookup needs to pass three parameters, the first is the keyfields parameter, which is used to specify which field search, the second is the keyVALUES parameter, used to specify the corresponding value of each field, the third is the ResultFields parameter, used to specify Which fields to return. The following example searches CustTable Company field in the value "Professional Ltd." record, and returns the value Company, Contact, Phone and other fields: varLookupResults: Variant; BeginWith CustTable DoLookupResults: = Lookup ( 'Company', 'Professional Divers , Ltd. ',' company; contact; phone '); end; if the resultfields parameter specifies multiple fields, Lookup returns an array of variable types. If you do not find a match, lookup will return an empty array. Program example: varLookupResults: Variant; BeginWith CustTable DoLookupResults: = Lookup ( 'Company; City', VarArrayOf ([ 'Sight Diver', 'Christiansted']), 'Company; Addr1; Addr2; State; Zip'); End; 6.6 Filtering an application is often only interested in partial record of the data set, for example, may only be interested in customers from Guangdong in a client table. In this case, filtering techniques can be filtered out with a record of specific conditions. However, for a lot of data sets, it is best to use queries. 6.6.1 Allow Filter to filter the dataset, first specify the filter condition, and set the FilterOptions property to set the option (optional), and set the filter attribute to true. If you don't want to filter, just set the filter attribute to false. There are two ways to specify filtering conditions: First, set the filter attribute, the second is to give the filter condition in the handle of the ONFILTERRECORD event. The Filter property is suitable for use in the runtime, which is capable of dynamically specifying filtering conditions, and can change filter conditions as needed. However, the Filter property is a string, and the filtering conditions are relatively simple. Although the operator can form a composite conditional expression, it is limited to several common operators. More importantly, only other field names and constants in the data set are specified by the Filter property, and other data cannot occur. The ONFILTERRECORD event is much flexible, it can specify a filtration condition during the design period. In the handle of the ONFILTERRECORD event, filter conditions can be arbitrarily specified, and filter conditions can be complicated.
6.6.2 Filter Properties Filter Property is a string, which can set the filter attribute: DataSet1.filter: = '' 'state' '' = '' ca '' '; can also set the filter property: DataSet1.Filter: = Edit1 .Text; The above line code allows users to enter the filtering criteria. It can even combine the above two lines: DataSet1.filter: = '' 'State' '=' edit1.text; After the filtering is set, simply set the filter attribute to true, filtering is valid. Composite filtration conditions can be constructed with comparison and logical operators, including:
For example, in order to ignore the case when the STATE field is compared, it can be set: filterOptions: = [FOCASEINSENSITIVE]; filter: = '' '' '' = '' ca ''; 6.6.5 Browse after filtered data Recording the filtered data set is actually a subset of the original data set. TDataSet provides four ways to browse records in a filtering data set, which is: .findFirst makes the first record in the filtering data set becomes the current record; .findlast makes the last record in the filtered data set becomes the last record in the filter. Current record; .findNext makes the next record in the filtered data set into the current record; .findprior records the previous record in the filtered data set into the current record. The above four methods If the call is successful, return TRUE, otherwise, return false. You can check a read-only Found property to see if the last call is successful. If the filter condition is set via the Filter property or the ONFilterRecord event, the Filtered property is set to false, and the above four methods are called automatically, and the filter is automatically allowed, and then the location of the current record is moved, and finally the filtering is prohibited. In other words, the above four methods can ignore how the Filtered property is set. If the filter condition is not set, the above four methods are equivalent to First, Last, Next, and Prior. 6.7 Modifying Data TDataSet provides some ways to update, insert, and delete records in data sets, they are: .edit makes the dataset into the dsedit status; .Append Add a record at the end of the data set; .insert in the data set The current location is inserted into a record; .post tries to write the user to the data set; .cancel cancels the user's modification of the data, so that the dataset is returned to the DSBROWSE state; .delete deletes the current record. 6.7.1 Enter the Dsedit Status To edit the record of the data set, first enter the Dsedit status. To enter the Dsedit state, call the Edit function. However, calling Edit does not necessarily enable the data set into the DSEDIT state, but also on the value of the canmodify attribute. Once the data set enters the DSEDIT state, the user can modify the current record on the data control. When the user removes the input focus from the current record, it is equivalent to calling the POST function. The program example is, for example, the CustTable DobeGineDit; FieldValues ['Custno']: = 1234; POST; END; to cancel the currently unresser modification, the user can press the ESC button or click the CANCEL button on the navigator implemented with the TDBNAVigator component. When using the cache update technology (CacheDuPdates property is set to true), calling POST just writes the data to the cache, not directly written to the data set. To write the data in the cache to a data set, you need to call the ApplyUpdates function. 6.7.2 Inserting a new record To insert a new record in the data set, first go to the DSInsert state. To enter the DSInsert state, you can call the INSERT or APPEND function. However, calling INSERT or APPEND does not necessarily enable the data set into the DSIrt state, but also on the value of the canmodify property. Once the DSInsert state is entered, the user can insert a new record in the data control (typically TDBGRID) and record this record. If you want to insert a new record by programming, you should pay attention to the difference between INSERT and APPEND. INSERT will insert a new record into the front of the current record, and Append will add a new record to the end of the data set.
After inserting a new record, call POST or call ApplyUpdates to write new records to the data set in the case where the cachedupdates property is set to TRUE. If the data set is a PARADOX or DBASE table that has established an index, the new record will be automatically moved to the appropriate location. If the data set does not establish an index, the new record is inserted into the current location of the data set (INSERT) or the end (Append). 6.7.3 Deleting Record Calling the delete function will delete the current record and make the dataset back to the DSBROWSE state. If there is a TDBNAVigator component on the form, the user can click the "Delete" button on the navigator to delete the current record. After the current record is deleted, the next record is the current record. If the deleted is the last record, the previous record becomes the current record. 6.7.4 Modifying the entire record In addition to TDBGRID and TDBNAVigator, most of the data controls can only work on one or several fields of the dataset, not the entire record. However, TDataSet provides several ways to directly modify the entire record instead of a separate field, including: .AppendRecord is similar to the append, but can assign a value to the field, do not need to call post ;. InsertRecord is similar to INSERT, but you can give Field assignment, do not need to call post ;.SetFields assign values to the current recorded field, need to be explicitly calling POST. All of the three methods described above are transmitted to an array of TvarRec types as a parameter, and each element of the array corresponds to a value of a field. If the array is less than the number of fields of the data set, the value of the remaining field is NULL. For data sets that have not established indexes, AppendRecord adds a new record to the end of the data set. For data sets that have established indexes, new records will be automatically moved to an appropriate location. SetFields is used to assign a value for the current recorded field. Before calling setfields, you first call Edit to enable the dataset into the Dsedit state. After calling setfields, you need to explicitly call the POST function. When you call SetFields, if you only want to assign a value for some fields, let the value of other fields remain unchanged, you can use null or nil to assign a value. Suppose there are five fields in a data set, named, Capital, Continent, Area, and Population, you can assign them: CountryTable.InsertRecord (['japan', 'tokyo', 'asia']); the above program is in data A new record is concentrated and the value is assigned to the first three fields. Now you can assign the current record, but this time you just want to assign a value for the area field and the population field, the program should write: with CountryTable Dobeginif Locate ('Name', 'Japan', LocaseInSitive) Thenbeginedit; SetFields (Nil, NIL) , NIL, 344567, 164700000); Post; end; end; Note: Use NIL instead of null, otherwise, the first three fields will be set to empty.
6.8 Event TDataSet The event is mainly divided into two categories. One type is the Before series, the other is the AFTER series, the list is as follows: .beforeopen, afteropen happens before and after the dataset is opened; .beforeclose, afterclose occurs before and after the data set; .BeForeInsert, AfterInsert happened before and after inserted a new record; .beForeEdit, Afteredit occurred before and after entering the Dsedit state; .beforepost, afterpost happened before and after the write dataset; .beforeCancel, AfterCancel happened before and after canceling; .beforcetelete After Delete occurs before and after the record. In addition, the ONNEWRECORD event is triggered when a new record is added to the data set, and the oncalcfields event will be triggered when the value of the "calculating field" needs to be returned. The BEFORE series is often used to abort the operation. For example, when the DELETE function attempts to delete the current record, the BeforeDelete event will be triggered before the current record will be deleted. You can call Abort or trigger an exception to delete the current record in the handle of the BeforeDelete event. (DataSet: TDataSet) Beginif Messagedlg ('delete this record?', MTConfirmation, mbyesnocancel, 0) <> MRYES THEN ABORT; END; AFTER series events are often used to notify users on the status bar, and the program is as follows: Procedure TFORM1. Table1AFTERDELETE (DataSet: TDataSet); beginstatusbar1.simpletext: = format ('has% D record', [Dataset.RecordCount]); end; oncalcfields event is mainly used to give the "calculation field" value. The value of the AutoCalcFields property determines when the oncalcfields event will occur. If the AutoCalcFields property is set to true, the oncalcfields event will occur when the data set is opened;. In the data control, the input focus moves from one record to another record; in the data control, enter the focus from a field Move to another; the current record is modified or retrieved from the database. However, even if the AutoCalcFields property is set to False, the oncalcfields event is triggered when the value of any of the non-calculated fields in the data set changes. Since the oncalcfields event is likely to occur frequently, the code to process the oncalcfields event is as short as possible. In the case where the AutoCalcFields property is set to TRUE, the data of the data set cannot be modified in the handle of the ONCALCFIELDS event, because once the current record is modified, the oncalcfields event is also triggered, resulting in an infinite loop. For example, suppose you call POST in the handle that handles the oncalcfields event, it will trigger the oncalcfields event, resulting in calling the POST again, triggering the oncalcfields event again ... 6.9 TBDedataset tbdedataset is inherited from tdatan, it provides BDE (BorlandDatabase Engine) ) The ability to access the data.
This section mainly introduces TBDedataset, readers should have a more profound understanding of TDataSet described earlier. Like TDataSet, TBDedataset is also virtual and abstract unless you want to create a custom dataset, otherwise, it is generally not required to use TBDedataset. TBDedataset recommends the method of recording navigation, indexing, and bookmarks in TDataSet, adds some properties, methods, and events that process blob fields, cache updates. 6.9.1 Cacheblobs Attribute TBDedataset The cacheblobs property is used to control whether the BDE puts the contents of the BLOB field in the cache. If this property is set to true, when the application reads the value of the blob field, BDE will put the contents of the BLOB field in the cache, so that when the application reads the value of this field next time, no need to The database server retrieves, as long as it is taken directly from the memory, this can improve the performance of the application. However, if the application needs to update the value of the blob field frequently, then the cacheblobs property should be set to false so that the value of the retrieved BLOB field is always the latest. 6.9.2 Cache Update TBDedataset provides a technology for cache updates. The so-called cache update is that the application retrieves data from the database, establish a copy in the local cache, and the user is modified to the data, it is only reflected in the cache, and Applyupdates can be called all modifications to the data set in the data set. . It can be seen that the cache update technology can significantly improve the performance of the application, and can easily cancel the modification, as long as Applyupdates have not been called. The following listings are listed in the TBDedataSet, methods, and events about cache updates: .cachedupdates If this property is set to true, the cache update is valid; .updateObject is used to specify a TUPDATESQL component to update the query-based data set; .updatepending If the cache There is a non-final record, this property returns true ;.updateRecordtypes specifies which records in the data set is visible; .updateStatus returns the current update status; .onUpdateError will trigger this event if the error will trigger the event; .onupdateRecord each updated one record This event will be triggered; .applyupdates write the data in the cache to the data set; .cancelupdates cancels the unresolved modifications in the cache; .commitUpdates cleared the cache; l FetChall Retrieves all records from the database to the cache; .revertRecord undo Modifications to the current record. 6.10 TDBDataSet TDBDataSet is inherited from TBDedataset, which provides the ability of database and session management. Several properties and methods are added to manage databases and BDE sessions, including: .Checkopen Check that the database is turned on ;.Database returns a TDATABASE component ;.dbhandle returns a BDE handle, call the BDE API to use This handle; .dblocale returns the current international language driver ;.dbsession returns a BDE session period object ;.DatabaseName is used to specify the database to be accessed; .SessionName is used to specify a BDE session. Here, explain the DatabaseName property and the sessionname property. If the application is to access the remote database server such as Sybase, Oracle or InterBase, you should use the TDatabase component to connect to the database. At this time, you should set the databaseName property to specify the database to be connected, which can be set to the name of the TDATABASE component.