如果你用的是Table
var index,dec_index:TIndexDef;i,count:Integer;field:TField;
indexname:AnsiString;
begin
count:=Table1.FieldCount;
for i:=0 to count-1do
begin
field:=Table1.Fields.Fields;
indexname:=field.FieldName;
if (Table1.IndexDefs.IndexOf(indexname)=-1) and
(field.FieldKind<>fkCalculated) then
begin
index:=Table1.IndexDefs.AddIndexDef;
index.Name:=indexname;
index.Fields:=field.FieldName;
end;
end;
end;
指定Table的IndexName即可排序
如果是Query可以加一个TClientDataSet和TDataSetProvider组件
用类似的方法实现。