重生之风流大明星下载:ELIB排序函数
来源:百度文库 编辑:九乡新闻网 时间:2024/10/06 01:25:51
Ehlib3.0版本以上虽然支持排序功能,但不支持带有Order By的SQL语句,而且排序很慢;我写的这个排序函数,利用ADO的sort方法,排序很快,几万条数据也是很快。该函数支持Lookup字段排序,不支持计算字段排序,因为计算字段值在内存里高速运算。排序分为:升序、降序和默认三种,支持排序图标。procedure SortDBGridEh(Sender: TObject; ACol: Integer;
Column: TColumnEh);
var
FieldName, SortStr: string;
begin
Screen.Cursor := crSQLWait;
try
if (Sender is TDBGridEh) and
((Sender as TDBGridEh).DataSource.DataSet <> nil) then
begin
if not ((Sender as TDBGridEh).DataSource.DataSet is TCustomADODataSet) then
Exit; if not (Sender as TDBGridEh).DataSource.DataSet.Active then
Exit; FieldName := Column.FieldName;
if (Sender as TDBGridEh).DataSource.DataSet.FindField(FieldName).IsBlob then
Exit; if (Sender as TDBGridEh).DataSource.DataSet.FieldByName(FieldName).FieldKind =
fkData then
SortStr := FieldName
else if (Sender as TDBGridEh).DataSource.DataSet.FieldByName(FieldName).FieldKind =
fkLookup then
FieldName := (Sender as TDBGridEh).DataSource.DataSet.FieldByName(FieldName).KeyFields
else
FieldName := ''; if (FieldName = '') or (Pos(';', FieldName) > 0) then
Exit;
case Column.Title.SortMarker of
smNoneEh:
begin
Column.Title.SortMarker := smUpEh;
TCustomADODataSet((Sender as TDBGridEh).DataSource.DataSet).Sort :=
FieldName; end;
smUpEh:
begin
Column.Title.SortMarker := smDownEh;
TCustomADODataSet((Sender as TDBGridEh).DataSource.DataSet).Sort :=
FieldName + ' DESC';
end;
smDownEh:
begin
Column.Title.SortMarker := smNoneEh;
TCustomADODataSet((Sender as TDBGridEh).DataSource.DataSet).Sort := '';
end;
end;
end;
finally
Screen.Cursor := crDefault;
end;
end;--程序实现如下:
--在DBGridEh的事件OnTitleBtnClick引用该函数即可:
procedure TFrmU_BasicSetup.dbgAddrCodeTitleBtnClick(Sender: TObject;
ACol: Integer; Column: TColumnEh);
begin
SortDBGridEh(Sender, ACol, Column);
end;
--为了保证表格的每一列都能点击触发排序,你需要将你需要排序的列属性
-- Title->TitleButton设置为True。
Column: TColumnEh);
var
FieldName, SortStr: string;
begin
Screen.Cursor := crSQLWait;
try
if (Sender is TDBGridEh) and
((Sender as TDBGridEh).DataSource.DataSet <> nil) then
begin
if not ((Sender as TDBGridEh).DataSource.DataSet is TCustomADODataSet) then
Exit; if not (Sender as TDBGridEh).DataSource.DataSet.Active then
Exit; FieldName := Column.FieldName;
if (Sender as TDBGridEh).DataSource.DataSet.FindField(FieldName).IsBlob then
Exit; if (Sender as TDBGridEh).DataSource.DataSet.FieldByName(FieldName).FieldKind =
fkData then
SortStr := FieldName
else if (Sender as TDBGridEh).DataSource.DataSet.FieldByName(FieldName).FieldKind =
fkLookup then
FieldName := (Sender as TDBGridEh).DataSource.DataSet.FieldByName(FieldName).KeyFields
else
FieldName := ''; if (FieldName = '') or (Pos(';', FieldName) > 0) then
Exit;
case Column.Title.SortMarker of
smNoneEh:
begin
Column.Title.SortMarker := smUpEh;
TCustomADODataSet((Sender as TDBGridEh).DataSource.DataSet).Sort :=
FieldName; end;
smUpEh:
begin
Column.Title.SortMarker := smDownEh;
TCustomADODataSet((Sender as TDBGridEh).DataSource.DataSet).Sort :=
FieldName + ' DESC';
end;
smDownEh:
begin
Column.Title.SortMarker := smNoneEh;
TCustomADODataSet((Sender as TDBGridEh).DataSource.DataSet).Sort := '';
end;
end;
end;
finally
Screen.Cursor := crDefault;
end;
end;--程序实现如下:
--在DBGridEh的事件OnTitleBtnClick引用该函数即可:
procedure TFrmU_BasicSetup.dbgAddrCodeTitleBtnClick(Sender: TObject;
ACol: Integer; Column: TColumnEh);
begin
SortDBGridEh(Sender, ACol, Column);
end;
--为了保证表格的每一列都能点击触发排序,你需要将你需要排序的列属性
-- Title->TitleButton设置为True。
ELIB排序函数
Excel函数排序与筛选
实例教你学Excel函数排序与筛选
Excel中自定义函数\自定义排序\隐藏数据\打印工资条
Excel中怎样自定义函数\自定义排序\隐藏数据\打印工资条
列表排序
冒泡排序
座次排序
随机排序(点歌排序)
Word2003表格排序 Word2007表格排序[1]
Word2003表格排序 Word2007表格排序[2]
Word2003表格排序 Word2007表格排序[3]
函数与函数指针
COUPDAYBS 函数 (财务函数)
COUPDAYS 函数(财务函数)
DDB函数(函数)
中国历史朝代排序.
中国皇帝排序【珍藏】
Excel数据排序
十大元帅排序
中国皇帝排序
姓氏笔画排序表
水浒一百单八将排序
修改ASE排序集