ClientDataSet implies ------ Reprinted "Delphi from Getting Started" May be repeated with the previous notes with repetitive places where ClientDataSet components support a lot of features, some of which are related to the three-level structure, and can also be used in other environments . This component illustrates a database full image in memory, which makes dynamic operations, such as establishing an index, other data sets typically do not support this feature. For example, in order to classify query, we usually re-execute it. In order to index a local table, you need to define an index. Only ADO data set has some dynamic index functions as ClientDataSet. Indexes are not all the features provided by ClientDataSet. When we have an index, we can be based on its definition group, which may be multi-level packets. For a location recorded in the group (head, tail or intermediate position), even specifically supported. In groups or entire data tables, we can define a total; that is, you can dynamically calculate the sum or average of the entire table or the current group. Data does not need to be sent to physical servers because these total operations occur in memory. We can even define new total fields and can be connected directly to the data sensitive control. Note that all these features can not only be used with the MIDAS application, but also with the client / server, even partial thinning applications. In fact, the ClientDataSet component can connect from remote MIDAS, local data collection (establishing data snapshot), or local files (just like in the briefcase mode, but use only the entire table defined in the client data collection) A data is obtained. This is another area that needs to be studied, so it will demonstrate two examples to highlight key features. These examples are not based on MIDAS, but based on local forms. 1. A interesting feature that defines the data type of abstract data VCL database support is that when we use ClientDataSet based on local files, you can define an abstract data type. Simply place a ClientDataSet component on the form, activate the editor for the Fielddefs property, add two fields and select the ftadt value for their DataType properties. Now, move to the childdefs attribute, and define the subfield, the following is the field definition of the ADTDEMO example: Fielddefs =
We can provide its compressed value by defining the onGetText event (there is a default value in Delphi4, but Delphi5 is not): procedure tform1.clientDataSet1NameGetText (Sender: tfield; var text: string; displaytext: boolean; begin text : = ClientDataSet1NameFirstName.Asstring '' ClientDataSet1NameLastname.Asstring; End; 2, Dynamic Index Once there is data on the ClientDataSet, the data is all in memory. When we start the component based on the local file (as in the ADTDemo paradigm), the entire file is loaded to the total memory. This is different from the loading data from the Paradox data table (the field that is only loaded) is different. The advantage of putting the entire table in memory is that we can quickly classify it. With the ClientDataSet component, we can achieve classification by assigning the field names corresponding to the indexfieldnames property. In ADTDEMO (and many programs), the index change will execute when clicking the title of the DBGRID control: procedure tform1.dbgrid1titleclick (Column: tcolumn); begin if color.field.FullName = 'name' Then ClientDataSet1.indexfieldNames: = 'name.lastname' else clientDataSet1.indexfieldNames: = column.field.FullName; end; Due to the ADT definition, the program uses the FullName property of the field (not the FieldName property). In fact, for subfields, the index should be based on Name.lastName instead of LastName. And the ADT field cannot be indexed by itself, so if you select it, the program uses the lastname subfield as an index. These indexes are not persistent; they are not saved in the file, but only in memory is applied to data. Tip: ClientDataSet can have indexes based on calculating fields, especially internal calculation fields, which can only be used for this data set. 3. Once a group defines an index once the clientDataSet is defined, the data can be packetized by the index. In fact, a group defined as a list of continuous records (according to index), the value of the fields that are indexed in the record will not change. For example, if there is a country-based index, all addresses with the country will be classified as a group. The CDSCalcs example has a ClientDataSet component, which also reads its data from the Country table of the DBDemos database. This operation can be executed when designing, using the ASSIGN LOCAL DATA command of the ClientDataSet Component Shortcut Menu.
In order to read data at runtime, get a Updated snapshot, you can add a DataSetProvider component to the form, connect three components as follows: Object Table: TTable Active = true databasename = 'dbdemos' TableName = 'country.db' end Object DataSetProvider1: TDataSetProvider DataSet = Table1 End Object ClientDataSet1: TclientDataSet Provider = 'DataSetProvider1' End Let's take a look at the definition of the group. This definition can specify a packet level as an index to obtain the index together define: object clientdataset1: tclientdataset indexdefs =