Research on TDataSet
There is a very important abstract class called TDataSet in the database framework of the VCL, which can handle non-BDE data sources.
Given that many database perceived controls in Delphi are connected as interfaces and databases, in order to reuse existing resources in Delphi, our small database has been more robust and more portable, and public interface has been proposed, and the interface programming, Therefore, it is decided to override the original GPF control by tdataaset.
TDataSet itself has packaged the recording buffer system. Buffers is to record its recording buffer. BufferCount records can be used in the number of buffers. But the number of buffers is more than BufferCount. One of these is TDataSet used as a temporary buffer, ie TempBuffer. Although TDataSet has been encapsulated, all implementations of the buffer are also achieved in derived classes. But all can be implemented outside is a single recording buffer. Such as: to record buffer application space, release space, initialization buffer, and some operations related to the buffer. These in the "Delphi 5 Developer Guide" in Section IV "Extended TDataSet has a good description.
Record buffer list
Temporary buffer
0
1
2
3
.
.
.
At last
temporary
Figure 1: Recording a buffer list structure
Since TDataSet is an abstract class, all abstraction methods must be implemented in derived classes. Implementing these abstract methods is also to achieve our GPF (now renamed GDB). Because it is the connection of DataSet and database data for these abstractions. The most basic is two methods for INTERNALOPEN and INTERNALCLOSE. In addition, you must implement GetFieldData, SetFieldData. Here is a point to explain that the order in Fields (ie, the order in which field [i] access is used) and the sequence of fields in the database are different. I have made a mistake here. My solution is to use the properties in the field fieldNO, which can record the physical location of this field. Then use FieldBynumber to access the field. (Is it a bit trouble? I have no way to do it). Of course, you can also record Fields in the original order with a list.
The record number in the TDataSet is that this property is used to represent the current access order, in the record, in the current access order. The display of the perceived control also depends on this attribute. It is not used to represent the physical sequence of records. Therefore, when implementing, an internal management record is used in an internal management record, which is equivalent to an internal cursor.
There are several methods that have not mentioned in the Development Guide I want to explain that these are related to the display of the perceptual control, so they are under public.
Issquenced This function under public in the TDataSet should inherit. This method is used to represent whether the recording is continuous and compact. This feature is used in the database sensation control. For example, the state of the vertical scroll bar in dBGrid is determined according to this. If the function returns true, it is to say that the record is compact, then the scroll bar determines the specific location according to Recno. Conversely, if it is a fake, the scroll bar has only three states, that is, the most, the middle, and at most.
CompareBookmark This function is used to determine the size of both records. Similarly, this function is also related to the perceptual control. After the DBGRID selected MultiSelect, when a record is selected, the GRID determines whether or not the adjacent record is determined based on the return value of the function. In fact, in this state, Grid will choose all the same records.
There is another function, getcanmodify is the realization of Canmodify. Override can be used to control the readonly of DataSet. I want to add a few words to the tempbuffer I said in the third paragraph. TempBuffer This buffer has a great role because it has the same features and operations as other buffers, and it is "survival self-management" for you. This will find it is useful when you implement query operations. You should already have a function of comparing two records, but when you queries, you only have a record and the query criteria can be used. This is where you can convert your query conditions into records, and this record can be placed in the TEMPBuffer. So your implementation will become very unified, because you do just two records comparison.
TDataSet additionally encapsulates a bookmark function (Bookmark). Under normal circumstances, Bookmark is only available in two member variables. One is a DATA (TBOOKMARK type), one is Flag (TBOOKMARKFLAG).
Data use to record that you can access the value of the record. This is a variable of a Pointer type. Therefore, you can use it as an integer (such as the memory number, I use it), or point to a recorded pointer, or even a record. The FLAG is used to record the location of the current label. TBOOKMARKFLAG in Delphi is the definition: tbookmarkflag = (BFCurrent, BFBOF, BFEOF, BFINSERTED); where BFCurrent is a current location, that is, a valid DATA. BfBof and BFEOF represent the first position. BFINSERTED means that it has just been inserted and has not been submitted (POST) record.
Understand the member variables required by Bookmark and its significance. Let's take a look at how Delphi in tdataset uses Bookmark. For the sake of convenience, I will first introduce the Bookmark I used when I realize GDB.
Below is the structure:
PgdbBookmarkInfo = ^ TGDBBOOKMARKINFO;
TGDBBOOKMARKINFO = Record
BookmarkData: Integer;
BookmarkFlag: TBOOKMARKFLAG;
END;
The first thing to solve is what is Bookmark places. This is actually invisible. Tell the recording buffer, in fact, Bookmark is after the recording buffer. Or more simply, the entire buffer is composed of records and Bookmark (TGDBBOOKMARKINFO structure).
Recording buffer
TGDBBOOKMARKINFO
Figure 2: Recording buffer structure
The operation of the buffer is implemented in the derived class of TDataSet. There are several abstract methods setBookmarkflag, SetBookmarkData, GetBookmarkData, getBookmarkFlag. These methods are to operate directly to the buffer.
TDataSet is to operate Bookmark using these methods. However, it is generally set up Bookmark to be implemented in inheritance classes. The location of the realization is actually imaginated. Since the Bookmark and the recording buffer are together, then when the recording buffer is operated (when reading to the buffer), it is also in the getRecord function, you can write the Bookmark associated with the record. As discussed above, you must fill in the corresponding value in BookMarkData. For example, you can fill in the record number. You can use the record number to access the record later.
INTERGOTOKOKMARK is to be recorded using BookMarkData. INTERNALSETTORECORD is also a similar operation. Another use of data perceived controls is CompareBookmarks. Its two parameters are TBOOKMARK types. You are based on this pointer to access the data you store. I can use Integer (Bookmark1 ^) as my implementation. In addition, according to my implementation, GetRecno can also be obtained by access to ActiveBuffer (recording the current active buffer).