B
bsense
Unregistered / Unconfirmed
GUEST, unregistred user!
//不用设置ehlib的autosortmark:=true,而且不能true<br>//这个函数是网上收集到的ado数据集的,我做了改进<br>//**************************************<br>//<br>// Ehlib 的 dbgrideh 里面排序的函数<br>// 是对网上的 Ado 版本 的修改<br>// 适用数据集 zeoslib 6.1 zquery <br>// delphi 7 ,windows xp<br>// 绵阳市卓易软件公司<br>// <br>//*********************<br>unit EhlibSort;<br><br>interface<br>uses Controls, DB, ZAbstractRODataset, ZAbstractDataset, ZDataset, GridsEh,<br>DBGridEh, forms;<br><br>procedure SortDBGridEh(Sender: TObject; ACol: Integer;<br> Column: TColumnEh);<br><br>implementation<br><br>procedure SortDBGridEh(Sender: TObject; ACol: Integer;<br> Column: TColumnEh);<br>var<br> FieldName, SortStr: string;<br>begin<br> Screen.Cursor := crSQLWait;<br> try<br> if (Sender is TDBGridEh) and<br> ((Sender as TDBGridEh).DataSource.DataSet <> nil) then<br> begin<br> if not ((Sender as TDBGridEh).DataSource.DataSet is TZQuery) then<br> Exit;<br><br> if not (Sender as TDBGridEh).DataSource.DataSet.Active then<br> Exit;<br><br> FieldName := Column.FieldName;<br> if (Sender as TDBGridEh).DataSource.DataSet.FindField(FieldName).IsBlob<br> then<br> Exit;<br><br> if (Sender as<br> TDBGridEh).DataSource.DataSet.FieldByName(FieldName).FieldKind =<br> fkData then<br> SortStr := FieldName<br> else<br> if (Sender as<br> TDBGridEh).DataSource.DataSet.FieldByName(FieldName).FieldKind =<br> fkLookup then<br> FieldName := (Sender as<br> TDBGridEh).DataSource.DataSet.FieldByName(FieldName).KeyFields<br> else<br> FieldName := '';<br><br> if (FieldName = '') or (Pos(';', FieldName) > 0) then<br> Exit;<br> case Column.Title.SortMarker of<br> smNoneEh:<br> begin<br> Column.Title.SortMarker := smUpEh;<br> TZQuery((Sender as TDBGridEh).DataSource.DataSet).SortedFields :=<br> FieldName;<br> TZQuery((Sender as TDBGridEh).DataSource.DataSet).SortType := stDescending;<br> end;<br> smUpEh:<br> begin<br> Column.Title.SortMarker := smDownEh;<br> TZQuery((Sender as TDBGridEh).DataSource.DataSet).SortedFields :=<br> FieldName;<br> TZQuery((Sender as TDBGridEh).DataSource.DataSet).SortType := stAscending;<br> end;<br> smDownEh:<br> begin<br> Column.Title.SortMarker := smUpEh;<br> TZQuery((Sender as TDBGridEh).DataSource.DataSet).SortedFields :=<br> FieldName;<br> TZQuery((Sender as TDBGridEh).DataSource.DataSet).SortType := stDescending;<br> end;<br> end;<br> end;<br> finally<br> Screen.Cursor := crDefault;<br> end;<br>end;<br><br>end.