2009-05-15 19:56:17 +00:00
|
|
|
{ This module from FPC port of RX components library
|
|
|
|
|
2010-03-05 21:57:25 +00:00
|
|
|
Copyright (C) 2005-2010 Lagunov Aleksey alexs@hotbox.ru and Lazarus team
|
|
|
|
original conception from rx library for Delphi (c)
|
2009-05-15 19:56:17 +00:00
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify it
|
|
|
|
under the terms of the GNU Library General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or (at your
|
|
|
|
option) any later version with the following modification:
|
|
|
|
|
|
|
|
As a special exception, the copyright holders of this library give you
|
|
|
|
permission to link this library with independent modules to produce an
|
|
|
|
executable, regardless of the license terms of these independent modules,and
|
|
|
|
to copy and distribute the resulting executable under terms of your choice,
|
|
|
|
provided that you also meet, for each linked independent module, the terms
|
|
|
|
and conditions of the license of that module. An independent module is a
|
|
|
|
module which is not derived from or based on this library. If you modify
|
|
|
|
this library, you may extend this exception to your version of the library,
|
|
|
|
but you are not obligated to do so. If you do not wish to do so, delete this
|
|
|
|
exception statement from your version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License
|
|
|
|
for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Library General Public License
|
|
|
|
along with this library; if not, write to the Free Software Foundation,
|
|
|
|
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
}
|
|
|
|
|
2007-08-10 22:15:51 +00:00
|
|
|
unit rxsortmemds;
|
|
|
|
|
|
|
|
{$mode objfpc}{$H+}
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
2009-05-15 19:56:17 +00:00
|
|
|
Classes, SysUtils, DB, RxDBGrid;
|
2007-08-10 22:15:51 +00:00
|
|
|
|
|
|
|
type
|
2009-08-17 17:50:27 +00:00
|
|
|
|
|
|
|
{ TRxMemoryDataSortEngine }
|
|
|
|
|
2009-12-10 22:02:14 +00:00
|
|
|
TRxMemoryDataSortEngine = class(TRxDBGridSortEngine)
|
2013-03-19 13:45:06 +00:00
|
|
|
protected
|
|
|
|
procedure UpdateFooterRows(ADataSet:TDataSet; AGrid:TRxDBGrid);override;
|
|
|
|
function EnabledFooterRowsCalc:boolean;override;
|
2007-08-10 22:15:51 +00:00
|
|
|
public
|
2014-02-08 11:02:58 +00:00
|
|
|
procedure Sort(FieldName: string; ADataSet:TDataSet; Asc:boolean; SortOptions:TRxSortEngineOptions);override;
|
2012-09-21 17:06:21 +00:00
|
|
|
procedure SortList(ListField:string; ADataSet:TDataSet; Asc: array of boolean; SortOptions: TRxSortEngineOptions);override;
|
2007-08-10 22:15:51 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
implementation
|
|
|
|
uses rxmemds;
|
|
|
|
|
2013-03-19 13:45:06 +00:00
|
|
|
type
|
|
|
|
THackRxMemoryData = class(TRxMemoryData);
|
|
|
|
THackRxColumnFooter = class(TRxColumnFooter);
|
2013-03-28 15:40:03 +00:00
|
|
|
THackDataLink = class(TDataLink);
|
|
|
|
THackDataSet = class(TDataSet);
|
|
|
|
THackRxDBGrid = class(TRxDBGrid);
|
2013-03-19 13:45:06 +00:00
|
|
|
|
|
|
|
procedure TRxMemoryDataSortEngine.UpdateFooterRows(ADataSet: TDataSet;
|
|
|
|
AGrid: TRxDBGrid);
|
|
|
|
var
|
2013-06-14 18:44:58 +00:00
|
|
|
i:integer;
|
2013-03-19 13:45:06 +00:00
|
|
|
Col:TRxColumn;
|
2013-03-28 15:40:03 +00:00
|
|
|
|
|
|
|
DHL:THackDataLink;
|
|
|
|
DHS:THackDataSet;
|
|
|
|
SaveState:TDataSetState;
|
|
|
|
SavePos:integer;
|
|
|
|
SaveActiveRecord:integer;
|
2013-03-19 13:45:06 +00:00
|
|
|
begin
|
|
|
|
if not Assigned(ADataSet) then exit;
|
|
|
|
|
2013-03-28 15:40:03 +00:00
|
|
|
DHL:=THackDataLink(THackRxDBGrid(AGrid).Datalink);
|
|
|
|
DHS:=THackDataSet(ADataSet);
|
|
|
|
SaveState:=DHS.SetTempState(dsBrowse);
|
|
|
|
|
|
|
|
SaveActiveRecord:=DHL.ActiveRecord;
|
|
|
|
DHL.ActiveRecord:=0;
|
|
|
|
SavePos:=ADataSet.RecNo;
|
|
|
|
|
|
|
|
|
|
|
|
ADataSet.First;
|
|
|
|
while not ADataSet.EOF do
|
2013-03-19 13:45:06 +00:00
|
|
|
begin
|
2013-03-28 15:40:03 +00:00
|
|
|
|
2013-03-19 13:45:06 +00:00
|
|
|
for i:=0 to AGrid.Columns.Count-1 do
|
|
|
|
begin
|
|
|
|
Col:=TRxColumn(AGrid.Columns[i]);
|
|
|
|
if THackRxColumnFooter(Col.Footer).ValueType in [fvtSum, fvtAvg, fvtMax, fvtMin] then
|
2013-03-28 15:40:03 +00:00
|
|
|
THackRxColumnFooter(Col.Footer).UpdateTestValueFromVar( ADataSet.FieldByName(Col.Footer.FieldName).Value);
|
2013-03-19 13:45:06 +00:00
|
|
|
end;
|
2013-03-28 15:40:03 +00:00
|
|
|
|
|
|
|
ADataSet.Next;
|
|
|
|
end;
|
|
|
|
|
|
|
|
DHS.RecNo := DHL.RecordCount + SavePos + 1;
|
|
|
|
|
|
|
|
while not ADataSet.BOF do
|
|
|
|
begin
|
|
|
|
if SavePos = ADataSet.RecNo then
|
|
|
|
break;
|
|
|
|
ADataSet.Prior;
|
2013-03-19 13:45:06 +00:00
|
|
|
end;
|
|
|
|
|
2013-03-28 15:40:03 +00:00
|
|
|
DHL.ActiveRecord:=SaveActiveRecord;
|
|
|
|
DHS.RestoreState(SaveState);
|
2013-03-19 13:45:06 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TRxMemoryDataSortEngine.EnabledFooterRowsCalc: boolean;
|
|
|
|
begin
|
|
|
|
Result:=true;
|
|
|
|
end;
|
|
|
|
|
2014-02-08 11:02:58 +00:00
|
|
|
procedure TRxMemoryDataSortEngine.Sort(FieldName: string; ADataSet: TDataSet;
|
|
|
|
Asc: boolean; SortOptions: TRxSortEngineOptions);
|
2007-08-10 22:15:51 +00:00
|
|
|
begin
|
|
|
|
if Assigned(ADataSet) then
|
2014-02-08 11:02:58 +00:00
|
|
|
(ADataSet as TRxMemoryData).SortOnFields(FieldName, seoCaseInsensitiveSort in SortOptions, not Asc);
|
2009-08-17 17:50:27 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TRxMemoryDataSortEngine.SortList(ListField: string;
|
2012-09-21 17:06:21 +00:00
|
|
|
ADataSet: TDataSet; Asc: array of boolean; SortOptions: TRxSortEngineOptions);
|
2009-08-17 17:50:27 +00:00
|
|
|
begin
|
|
|
|
if Assigned(ADataSet) then
|
2012-09-21 17:06:21 +00:00
|
|
|
(ADataSet as TRxMemoryData).SortOnFieldsEx(ListField, seoCaseInsensitiveSort in SortOptions, Asc);
|
2007-08-10 22:15:51 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
initialization
|
2012-09-27 14:27:35 +00:00
|
|
|
RegisterRxDBGridSortEngine(TRxMemoryDataSortEngine, 'TRxMemoryData');
|
2007-08-10 22:15:51 +00:00
|
|
|
end.
|
|
|
|
|