begin with DBGrid0.DataSource.DataSet as TTable do //Table0 begin //检测当前工作表是否已打开 if not Active then begin MessageBeep(0); Application.MessageBox('工作表尚未打开!','停止',MB_OK+MB_ICONSTOP); Abort end;
//检测当前字段是否“能排序”。以下字段类型不能排序 case Column.Field.DataType of ftBoolean, ftBytes, ftBlob, //Binary ftMemo, ftGraphic, ftFmtMemo, //Formatted memo ftParadoxOle: //OLE begin MessageBeep(0); Application.MessageBox(Pchar('项目"'+Column.FieldName+'"'+'不能排序!'),'停止',MB_OK+MB_ICONSTOP); Abort end; end; //case mode:='0'; iCol:=Column.Field.FieldNo-1; try ColName:=Column.fieldname; if psIndexName=Column.fieldname then begin //与原来同列 if plAscend //升序 then begin mode:='2'; IndexName:=ColName+'2'; //应“降序” end else begin mode:='1'; IndexName:=ColName+'1'; //应“升序” end; plAscend:=not plAscend; end else begin //新列 IndexName:=ColName+'2'; plAscend:=false; psIndexName:=ColName; end; except on EDatabaseError do //若未有索引,则重新建立 begin Messagebeep(0); //以下新建索引 IndexName:=''; Close; Exclusive:=true; if mode='1' then AddIndex(ColName+'1',ColName,[ixCaseInsensitive],'')// else //包括'0' AddIndex(ColName+'2',ColName,[ixDescending,ixCaseInsensitive],''); Exclusive:=false; Open; try //try 1 if mode<>'1' then begin mode:='2';//转换 plAscend:=false; end else plAscend:=true; IndexName:=ColName+mode; psIndexName:=ColName; except on EDBEngineError do IndexName:=''; end //try 2 end end; First; end; //with DBGrid0.SelectedIndex:=iCol; end;//End of MySort
Copyright 2001-2010, www.comprg.com.cn, All Rights Reserved 京ICP备14022230号-1,电话/传真:010-82561037 82561614 ,Mail:gaojian@comprg.com.cn
地址:北京市海淀区远大路20号宝蓝大厦E座704,邮编:100089