?? ehlibmte.pas
字號:
{*******************************************************}
{ }
{ EhLib vX.X }
{ Register object that sort data in }
{ TCustomClientDataSet }
{ }
{ Copyright (c) 2003 by Dmitry V. Bolshakov }
{ }
{*******************************************************}
{*******************************************************}
{ Add this unit to 'uses' clause of any unit of your }
{ project to allow TDBGridEh to sort data in }
{ TMemTableEh automatically after sorting markers }
{ will be changed. }
{ TMTEDatasetFeaturesEh determine if }
{ TDBGridEh.SortLocal = True then it will sort data }
{ in memory using procedure SortByFields }
{ else if SortLocal = False and MemTable connected to }
{ other DataSet via ProviderDataSet, it will try to }
{ sord data in this DataSet using }
{ GetDatasetFeaturesForDataSet function }
{*******************************************************}
unit EhLibMTE;
{$I EhLib.Inc}
interface
uses
{$IFDEF EH_LIB_6} Variants, {$ENDIF}
DbUtilsEh, DBGridEh, Db, MemTableEh, SysUtils;
type
TMTEDatasetFeaturesEh = class(TDatasetFeaturesEh)
public
procedure ApplySorting(Sender: TObject; DataSet: TDataSet; IsReopen: Boolean); override;
end;
implementation
uses Classes;
{ TMTEDatasetFeaturesEh }
procedure TMTEDatasetFeaturesEh.ApplySorting(Sender: TObject; DataSet: TDataSet; IsReopen: Boolean);
var
DS: TDataSet;
MTE: TCustomMemTableEh;
DatasetFeatures: TDatasetFeaturesEh;
i: Integer;
OrderByStr: String;
begin
if Sender is TCustomDBGridEh then
if TCustomDBGridEh(Sender).SortLocal then
with TCustomDBGridEh(Sender) do
begin
OrderByStr := '';
for i := 0 to SortMarkedColumns.Count - 1 do
begin
OrderByStr := OrderByStr + SortMarkedColumns[i].FieldName + ' ';
if SortMarkedColumns[i].Title.SortMarker = smUpEh then
OrderByStr := OrderByStr + ' DESC';
OrderByStr := OrderByStr + ',';
end;
Delete(OrderByStr, Length(OrderByStr), 1);
if (DataSet is TCustomMemTableEh) then
begin
MTE := TCustomMemTableEh(DataSet);
MTE.SortByFields(OrderByStr);
end;
end
else
begin
if not (DataSet is TCustomMemTableEh) then Exit;
DS := TCustomMemTableEh(DataSet).ProviderDataSet;
if DS <> nil then
begin
DatasetFeatures := GetDatasetFeaturesForDataSet(DS);
if DatasetFeatures <> nil then
DatasetFeatures.ApplySorting(Sender, DS, False);
DataSet.Close;
DataSet.Open;
end;
end;
end;
initialization
RegisterDatasetFeaturesEh(TMTEDatasetFeaturesEh, TCustomMemTableEh);
end.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -