ClientDataSet的動態排序

ClientDataSet 的動態排序能夠經過如下代碼實現
1.單一字段的升序和降序
with cds do
begin
  IndexDefs.Update;
  if IndexDefs.IndexOf('index1') >= 0 then
  DeleteIndex('index1');
  AddIndex('index1', SortFieldName, [], '');
  IndexName := 'index1';
  First;
end;

with cds do
begin
  IndexDefs.Update;
  if IndexDefs.IndexOf('index1') >= 0 then
  DeleteIndex('index1');
  AddIndex('index1', SortFieldName, [], SortFieldName);
  IndexName := 'index1';
  First;
end;

2.複合字段的升序和降序
with cds do
begin
  IndexDefs.Update;
  if IndexDefs.IndexOf('index2') >= 0 then
    DeleteIndex('index2');
  AddIndex('index2', 'SortField1, SortField2', [], '');
  IndexName := 'index1';
  First;
end;

with cds do
begin
  IndexDefs.Update;
  if IndexDefs.IndexOf('index2') >= 0 then
    DeleteIndex('index2');
  AddIndex('index2', 'SortField1, SortField2', [], 'SortField1, SortField2');
  IndexName := 'index2';
  First;
end;

3.複合字段的複合排序
傳入參數  SortField1, SortField2, [], SortField2 便可

http://blog.csdn.net/whw6_faye/article/details/1754084.net

相關文章
相關標籤/搜索