From c0f254ae832fd1e714a5ead2c4da911e089f7e1a Mon Sep 17 00:00:00 2001 From: alexs75 Date: Mon, 29 Jan 2018 11:34:23 +0000 Subject: [PATCH] RxFPC:add RxDBGrid sort engine for IBX git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@6154 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- components/rx/trunk/rx_sort_ibx.lpk | 42 +++++++++ components/rx/trunk/rx_sort_ibx.pas | 22 +++++ components/rx/trunk/rx_sort_ibx/exsortibx.pas | 90 +++++++++++++++++++ components/rx/trunk/rx_sort_ibx/rxsortibx.pas | 32 +++++++ 4 files changed, 186 insertions(+) create mode 100644 components/rx/trunk/rx_sort_ibx.lpk create mode 100644 components/rx/trunk/rx_sort_ibx.pas create mode 100644 components/rx/trunk/rx_sort_ibx/exsortibx.pas create mode 100644 components/rx/trunk/rx_sort_ibx/rxsortibx.pas diff --git a/components/rx/trunk/rx_sort_ibx.lpk b/components/rx/trunk/rx_sort_ibx.lpk new file mode 100644 index 000000000..301cb4641 --- /dev/null +++ b/components/rx/trunk/rx_sort_ibx.lpk @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/components/rx/trunk/rx_sort_ibx.pas b/components/rx/trunk/rx_sort_ibx.pas new file mode 100644 index 000000000..be471f6c8 --- /dev/null +++ b/components/rx/trunk/rx_sort_ibx.pas @@ -0,0 +1,22 @@ +{ This file was automatically created by Lazarus. Do not edit! + This source is only used to compile and install the package. + } + +unit rx_sort_ibx; + +{$warn 5023 off : no warning about unused units} +interface + +uses + RxSortIBX, exsortibx, LazarusPackageIntf; + +implementation + +procedure Register; +begin + RegisterUnit('RxSortIBX', @RxSortIBX.Register); +end; + +initialization + RegisterPackage('rx_sort_ibx', @Register); +end. diff --git a/components/rx/trunk/rx_sort_ibx/exsortibx.pas b/components/rx/trunk/rx_sort_ibx/exsortibx.pas new file mode 100644 index 000000000..5218553bd --- /dev/null +++ b/components/rx/trunk/rx_sort_ibx/exsortibx.pas @@ -0,0 +1,90 @@ +unit exsortibx; + +{$mode objfpc}{$H+} + +interface + +uses + Classes, SysUtils, DB, RxDBGrid; + +type + + { TZeosDataSetSortEngine } + + { TIBXDataSetSortEngine } + + TIBXDataSetSortEngine = class(TRxDBGridSortEngine) + protected + public + procedure Sort(FieldName: string; ADataSet:TDataSet; Asc:boolean; SortOptions:TRxSortEngineOptions);override; + procedure SortList(ListField: string; ADataSet: TDataSet; Asc: array of boolean; SortOptions: TRxSortEngineOptions); override; + end; + +implementation +uses IBCustomDataSet; + +function FixFieldName(S:string):string;inline; +begin + if not IsValidIdent(S) then + Result:='"'+S+'"' + else + Result:=S; +end; + +{ TIBXDataSetSortEngine } + +procedure TIBXDataSetSortEngine.Sort(FieldName: string; ADataSet: TDataSet; + Asc: boolean; SortOptions: TRxSortEngineOptions); +begin + if not Assigned(ADataSet) then exit; + + if ADataSet is TIBCustomDataSet then + begin + if Asc then + FieldName := FixFieldName(FieldName) + ' Asc' + else + FieldName := FixFieldName(FieldName) + ' Desc'; + TIBCustomDataSet(ADataSet).OrderFields:=FieldName; + end; +end; + +procedure TIBXDataSetSortEngine.SortList(ListField: string; ADataSet: TDataSet; + Asc: array of boolean; SortOptions: TRxSortEngineOptions); +var + S: String; + C: SizeInt; + i: Integer; +begin + if not Assigned(ADataSet) then exit; + + S:=''; + C:=Pos(';', ListField); + i:=0; + while C>0 do + begin + if S<>'' then S:=S+';'; + S:=S + FixFieldName(Copy(ListField, 1, C-1)); + Delete(ListField, 1, C); + + if (i<=High(Asc)) and (not Asc[i]) then + S:=S + ' DESC'; + C:=Pos(';', ListField); + inc(i); + end; + + if ListField<>'' then + begin + if S<>'' then S:=S+';'; + S:=S + FixFieldName(ListField); + if (i<=High(Asc)) and (not Asc[i]) then + S:=S + ' DESC'; + end; + + (ADataSet as TIBCustomDataSet).OrderFields:=S; +end; + +initialization + RegisterRxDBGridSortEngine(TIBXDataSetSortEngine, 'TIBQuery'); + RegisterRxDBGridSortEngine(TIBXDataSetSortEngine, 'TIBDataSet'); +end. + diff --git a/components/rx/trunk/rx_sort_ibx/rxsortibx.pas b/components/rx/trunk/rx_sort_ibx/rxsortibx.pas new file mode 100644 index 000000000..4c574e4f1 --- /dev/null +++ b/components/rx/trunk/rx_sort_ibx/rxsortibx.pas @@ -0,0 +1,32 @@ +unit RxSortIBX; + +{$mode objfpc}{$H+} + +interface + +uses + Classes, SysUtils; + +type + TRxSortIBX = class(TComponent) + private + + protected + + public + + published + + end; + +procedure Register; + +implementation +uses exsortibx; + +procedure Register; +begin + RegisterComponents('RX DBAware',[TRxSortIBX]); +end; + +end.