八神技巧集之七 Delphi用Ehlib,Zeoslib,实现自动排序的函数(1分)

  • 主题发起人 主题发起人 bsense
  • 开始时间 开始时间
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>&nbsp; Column: TColumnEh);<br><br>implementation<br><br>procedure SortDBGridEh(Sender: TObject; ACol: Integer;<br>&nbsp; Column: TColumnEh);<br>var<br>&nbsp; FieldName, SortStr: string;<br>begin<br>&nbsp; Screen.Cursor := crSQLWait;<br>&nbsp; try<br>&nbsp; &nbsp; if (Sender is TDBGridEh) and<br>&nbsp; &nbsp; &nbsp; ((Sender as TDBGridEh).DataSource.DataSet &lt;&gt; nil) then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; if not ((Sender as TDBGridEh).DataSource.DataSet is TZQuery) then<br>&nbsp; &nbsp; &nbsp; &nbsp; Exit;<br><br>&nbsp; &nbsp; &nbsp; if not (Sender as TDBGridEh).DataSource.DataSet.Active then<br>&nbsp; &nbsp; &nbsp; &nbsp; Exit;<br><br>&nbsp; &nbsp; &nbsp; FieldName := Column.FieldName;<br>&nbsp; &nbsp; &nbsp; if (Sender as TDBGridEh).DataSource.DataSet.FindField(FieldName).IsBlob<br>&nbsp; &nbsp; &nbsp; &nbsp; then<br>&nbsp; &nbsp; &nbsp; &nbsp; Exit;<br><br>&nbsp; &nbsp; &nbsp; if (Sender as<br>&nbsp; &nbsp; &nbsp; &nbsp; TDBGridEh).DataSource.DataSet.FieldByName(FieldName).FieldKind =<br>&nbsp; &nbsp; &nbsp; &nbsp; fkData then<br>&nbsp; &nbsp; &nbsp; &nbsp; SortStr := FieldName<br>&nbsp; &nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; &nbsp; if (Sender as<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TDBGridEh).DataSource.DataSet.FieldByName(FieldName).FieldKind =<br>&nbsp; &nbsp; &nbsp; &nbsp; fkLookup then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FieldName := (Sender as<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TDBGridEh).DataSource.DataSet.FieldByName(FieldName).KeyFields<br>&nbsp; &nbsp; &nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FieldName := '';<br><br>&nbsp; &nbsp; &nbsp; if (FieldName = '') or (Pos(';', FieldName) &gt; 0) then<br>&nbsp; &nbsp; &nbsp; &nbsp; Exit;<br>&nbsp; &nbsp; &nbsp; case Column.Title.SortMarker of<br>&nbsp; &nbsp; &nbsp; &nbsp; smNoneEh:<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Column.Title.SortMarker := smUpEh;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TZQuery((Sender as TDBGridEh).DataSource.DataSet).SortedFields :=<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FieldName;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TZQuery((Sender as TDBGridEh).DataSource.DataSet).SortType := stDescending;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; &nbsp; smUpEh:<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Column.Title.SortMarker := smDownEh;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TZQuery((Sender as TDBGridEh).DataSource.DataSet).SortedFields :=<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FieldName;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TZQuery((Sender as TDBGridEh).DataSource.DataSet).SortType := stAscending;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; &nbsp; smDownEh:<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Column.Title.SortMarker := smUpEh;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TZQuery((Sender as TDBGridEh).DataSource.DataSet).SortedFields :=<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FieldName;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TZQuery((Sender as TDBGridEh).DataSource.DataSet).SortType := stDescending;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; end;<br>&nbsp; finally<br>&nbsp; &nbsp; Screen.Cursor := crDefault;<br>&nbsp; end;<br>end;<br><br>end.
 
Zeoslib 记得2003或者在这之前使用过。<br>在连接SQLServer对中文的支持有些问题,比如中文字段的表名,存储过程也有问题,不知道现在最新的版本是否已经解决。
 
先在是高版本,6.x ,应该解决了,我没有测试过,也使用了存储过程,没有问题,新版本是 完全重新设计的,6.0以前 ,每个数据库的连接方式不同,现在都改到相同的使用模式了.
 
后退
顶部