Clientdataset Indexing and sorting

Source: Internet
Author: User

Indexes can be indexed using Clientdataset.addindex or CLIENTDATASET1.INDEXDEFS.ADDINDEXDEF.

Addindex (

Const name:string; Index name

Const fields:string; An indexed field, as of multiple use;

Options:tindexoptions; options [Ixprimary,ixunique,ixdescending,ixcaseinsensitive]

Const descfields:string; Descending sort Fields

Const caseinfields:string//Case-insensitive lowercase fields

Const Groupinglevel:integer//group level

);

Addindexdef usage similar to the above, set the corresponding property in With...do

With ClientDataSet1.IndexDefs.AddIndexDef do

Begin

name:string;

caseinsfields:string;

descfields:string;

expression:string;

fields:string;

Options:tindexoptions;

Groupinglevel:integer;

End

The following example uses the Addindex method:

*************************************************************************************************************** ************

Specific operation:

*************************************************************************************************************** ************

Dbgrid1.datasource->datasource1.dataset->clientdataset1.providername->datasetprovider1.dataset->

Sqldataset1.sqlconnection->sqlconnection1 specific database (this is connected to the EMP table in Oracle);

Sqldataset1.commandtext:=select * from EMP; Clientdataset1.active:=true;

*************************************************************************************************************** ************

Main code:

*************************************************************************************************************** ************

procedureTform3.button1click (sender:tobject);begin  ifClientdataset1.indexname='Index1'  Then  beginbutton1.caption:='ename ascending empno Descending'; Clientdataset1.indexname:='Index2'; End Else  beginClientdataset1.indexname:='Index1'; Button1.caption:='empno Ascending ename Descending'; End;End;procedureTform3.dbgrid1titleclick (column:tcolumn);beginif  notColumn.Field.IsBlob Then //cannot index or sort a binary fieldClientdataset1.indexfieldnames: =Column.fieldname;End;proceduretform3.formcreate (sender:tobject);begin   //empno Ascending sort ename descending orderClientdataset1.addindex ('Index1','EMPNO; Ename',[],'ename'); //can also be written  //clientdataset2.addindex (' Index1 ', ' empno,ename ', [ixdescending], ' ename ');//ixdescending is ignored  //ename Ascending, empno descendingClientdataset1.addindex ('Index2','EMPNO; Ename',[],'EMPNO'); Clientdataset1.indexname:='Index1';End;

Note: If you want to sort the data in the buffer only, use the Tempclientdataset.clonecursor method to clone to Tempclientdataset or directly with tempclientdataset.data:= Clientdataset1.data, the data in the ClientDataSet1 buffer is copied to Tempclientdataset, and the data in the ClientDataSet2 is separated from the data source, and then the Tempclientdataset is sorted. If you sort without separating the data source, ClientDataSet1 reads all the data from the table to the local reorder.

Clientdataset Indexing and sorting

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.