From 205588f98c2e7d6c140d6dc43ef75fb33f80b4e2 Mon Sep 17 00:00:00 2001 From: alexs75 Date: Fri, 18 Jan 2019 06:45:33 +0000 Subject: [PATCH] RxFPC: implement metod TRxMemoryData.SortOnFieldsEx git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@6794 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- .../rx/trunk/demos/AutoSort/AutoSortDemo.lpi | 177 ++++++++++++++++-- .../rx/trunk/demos/AutoSort/asdmainunit.lfm | 68 ++++--- .../rx/trunk/demos/AutoSort/asdmainunit.pas | 9 +- components/rx/trunk/demos/RxMDI/unit1.pas | 2 +- components/rx/trunk/rxdb/rxmemds.pas | 56 ++++-- components/rx/trunk/rxdb/rxsortmemds.pas | 2 +- 6 files changed, 261 insertions(+), 53 deletions(-) diff --git a/components/rx/trunk/demos/AutoSort/AutoSortDemo.lpi b/components/rx/trunk/demos/AutoSort/AutoSortDemo.lpi index 5d532cbff..fede88447 100644 --- a/components/rx/trunk/demos/AutoSort/AutoSortDemo.lpi +++ b/components/rx/trunk/demos/AutoSort/AutoSortDemo.lpi @@ -1,7 +1,7 @@ - + @@ -17,15 +17,19 @@ - - - - + + + + + + + + @@ -40,12 +44,12 @@ - + - + @@ -55,9 +59,9 @@ - - - + + + @@ -87,12 +91,151 @@ + + + + + + + + + + + + + + + + + + + + + + + - + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -110,6 +253,9 @@ + + + @@ -118,6 +264,11 @@ + + + + + diff --git a/components/rx/trunk/demos/AutoSort/asdmainunit.lfm b/components/rx/trunk/demos/AutoSort/asdmainunit.lfm index bf55e1410..25371000d 100644 --- a/components/rx/trunk/demos/AutoSort/asdmainunit.lfm +++ b/components/rx/trunk/demos/AutoSort/asdmainunit.lfm @@ -7,7 +7,7 @@ object Form1: TForm1 ClientHeight = 524 ClientWidth = 780 OnCreate = FormCreate - LCLVersion = '1.7' + LCLVersion = '2.1.0.0' object RxDBGrid1: TRxDBGrid AnchorSideLeft.Control = Owner AnchorSideTop.Control = CheckBox1 @@ -17,8 +17,8 @@ object Form1: TForm1 AnchorSideBottom.Control = Owner AnchorSideBottom.Side = asrBottom Left = 6 - Height = 452 - Top = 66 + Height = 454 + Top = 64 Width = 768 ColumnDefValues.BlobText = '(данные)' TitleButtons = True @@ -31,15 +31,29 @@ object Form1: TForm1 Width = 88 FieldName = 'ID' EditButtons = <> - Filter.IsNull = False - Filter.IsAll = True Filter.DropDownRows = 0 Filter.EmptyValue = '(Пусто)' + Filter.NotEmptyValue = '(Не пусто)' Filter.AllValue = '(All values)' Filter.EmptyFont.Style = [fsItalic] Filter.ItemIndex = -1 Footers = <> end + item + Title.Alignment = taCenter + Title.Orientation = toHorizontal + Title.Caption = 'TYPE' + Width = 70 + FieldName = 'TYPE' + EditButtons = <> + Filter.DropDownRows = 0 + Filter.EmptyValue = '(Пусто)' + Filter.NotEmptyValue = '(Не пусто)' + Filter.AllValue = '(Все значения)' + Filter.EmptyFont.Style = [fsItalic] + Filter.ItemIndex = -1 + Footers = <> + end item Title.Alignment = taCenter Title.Orientation = toHorizontal @@ -47,10 +61,9 @@ object Form1: TForm1 Width = 350 FieldName = 'NAME' EditButtons = <> - Filter.IsNull = False - Filter.IsAll = True Filter.DropDownRows = 0 Filter.EmptyValue = '(Пусто)' + Filter.NotEmptyValue = '(Не пусто)' Filter.AllValue = '(All values)' Filter.EmptyFont.Style = [fsItalic] Filter.ItemIndex = -1 @@ -63,10 +76,9 @@ object Form1: TForm1 Width = 100 FieldName = 'DATE_ENTER' EditButtons = <> - Filter.IsNull = False - Filter.IsAll = True Filter.DropDownRows = 0 Filter.EmptyValue = '(Пусто)' + Filter.NotEmptyValue = '(Не пусто)' Filter.AllValue = '(All values)' Filter.EmptyFont.Style = [fsItalic] Filter.ItemIndex = -1 @@ -129,6 +141,8 @@ object Form1: TForm1 Enabled = True end> FooterOptions.DrawFullLine = False + SearchOptions.QuickSearchOptions = [loCaseInsensitive, loPartialKey] + SearchOptions.FromStart = False OptionsRx = [] Anchors = [akTop, akLeft, akRight, akBottom] BorderSpacing.Around = 6 @@ -139,7 +153,6 @@ object Form1: TForm1 GridLineStyle = psSolid DataSource = Datasource1 Options = [dgEditing, dgTitles, dgIndicator, dgColumnResize, dgColumnMove, dgColLines, dgRowLines, dgAlwaysShowSelection, dgConfirmDelete, dgCancelOnExit, dgHeaderPushedLook] - ParentColor = False TabOrder = 0 TitleStyle = tsNative end @@ -148,9 +161,9 @@ object Form1: TForm1 AnchorSideTop.Control = CheckBox2 AnchorSideTop.Side = asrBottom Left = 6 - Height = 24 - Top = 36 - Width = 107 + Height = 23 + Top = 35 + Width = 108 BorderSpacing.Around = 6 Caption = 'Title buttons' OnChange = CheckBox2Change @@ -160,9 +173,9 @@ object Form1: TForm1 AnchorSideLeft.Control = Owner AnchorSideTop.Control = Owner Left = 6 - Height = 24 + Height = 23 Top = 6 - Width = 85 + Width = 86 BorderSpacing.Around = 6 Caption = 'Auto sort' OnChange = CheckBox2Change @@ -176,6 +189,10 @@ object Form1: TForm1 DataType = ftInteger Precision = -1 end + item + Name = 'TYPE' + DataType = ftInteger + end item Name = 'NAME' DataType = ftString @@ -188,8 +205,8 @@ object Form1: TForm1 Precision = -1 end> PacketRecords = 0 - left = 192 - top = 16 + Left = 192 + Top = 16 object RxMemoryData1ID: TLongintField DisplayWidth = 10 FieldKind = fkData @@ -200,11 +217,20 @@ object Form1: TForm1 ReadOnly = False Required = False end + object RxMemoryData1TYPE: TLongintField + FieldKind = fkData + FieldName = 'TYPE' + Index = 1 + LookupCache = False + ProviderFlags = [pfInUpdate, pfInWhere] + ReadOnly = False + Required = False + end object RxMemoryData1NAME: TStringField DisplayWidth = 100 FieldKind = fkData FieldName = 'NAME' - Index = 1 + Index = 2 LookupCache = False ProviderFlags = [pfInUpdate, pfInWhere] ReadOnly = False @@ -215,7 +241,7 @@ object Form1: TForm1 DisplayWidth = 10 FieldKind = fkData FieldName = 'DATE_ENTER' - Index = 2 + Index = 3 LookupCache = False ProviderFlags = [pfInUpdate, pfInWhere] ReadOnly = False @@ -224,7 +250,7 @@ object Form1: TForm1 end object Datasource1: TDataSource DataSet = RxMemoryData1 - left = 152 - top = 16 + Left = 152 + Top = 16 end end diff --git a/components/rx/trunk/demos/AutoSort/asdmainunit.pas b/components/rx/trunk/demos/AutoSort/asdmainunit.pas index 27e5faea1..313e9c919 100644 --- a/components/rx/trunk/demos/AutoSort/asdmainunit.pas +++ b/components/rx/trunk/demos/AutoSort/asdmainunit.pas @@ -41,6 +41,7 @@ type RxMemoryData1DATE_ENTER: TDateField; RxMemoryData1ID: TLongintField; RxMemoryData1NAME: TStringField; + RxMemoryData1TYPE: TLongintField; procedure CheckBox2Change(Sender: TObject); procedure FormCreate(Sender: TObject); private @@ -60,10 +61,10 @@ implementation procedure TForm1.FormCreate(Sender: TObject); begin RxMemoryData1.Open; - RxMemoryData1.AppendRecord([1, 'Delphi', EncodeDate(1995, 8, 1)]); - RxMemoryData1.AppendRecord([2, 'Turbo Pascal', EncodeDate(1983, 8, 1)]); - RxMemoryData1.AppendRecord([3, 'Free Pascal', EncodeDate(1993, 1, 1)]); - RxMemoryData1.AppendRecord([4, 'Lazarus', Now]); + RxMemoryData1.AppendRecord([1, 1, 'Delphi', EncodeDate(1995, 8, 1)]); + RxMemoryData1.AppendRecord([2, 1, 'Turbo Pascal', EncodeDate(1983, 8, 1)]); + RxMemoryData1.AppendRecord([3, 2, 'Free Pascal', EncodeDate(1993, 1, 1)]); + RxMemoryData1.AppendRecord([4, 2, 'Lazarus', Now]); CheckBox2.Checked:=RxDBGrid1.AutoSort; CheckBox1.Checked:=RxDBGrid1.TitleButtons; diff --git a/components/rx/trunk/demos/RxMDI/unit1.pas b/components/rx/trunk/demos/RxMDI/unit1.pas index cc67861b2..5ce76c9f7 100644 --- a/components/rx/trunk/demos/RxMDI/unit1.pas +++ b/components/rx/trunk/demos/RxMDI/unit1.pas @@ -97,7 +97,7 @@ begin else RxMDITasks1.Options:=RxMDITasks1.Options - [rxtoMidleClickClose]; - RxMDIPanel1.HideCloseButton:=optHideCloseButton.Checked; + RxMDIPanel1.HideCloseButton:=optHideCloseButton.Checked; ; end; procedure TForm1.Action1Execute(Sender: TObject); diff --git a/components/rx/trunk/rxdb/rxmemds.pas b/components/rx/trunk/rxdb/rxmemds.pas index 906cd8905..42a1ed6a3 100644 --- a/components/rx/trunk/rxdb/rxmemds.pas +++ b/components/rx/trunk/rxdb/rxmemds.pas @@ -64,6 +64,7 @@ type FIndexList: TList; FCaseInsensitiveSort: Boolean; FDescendingSort: Boolean; + FAscSortList: array of boolean; FFileName: string; FFileStream : TFileStream; @@ -505,6 +506,7 @@ begin FRecords.Free; ReallocMem(FOffsets, 0); if Assigned(FParser) then FreeAndNil(FParser); + SetLength(FAscSortList, 0); end; { Records Management } @@ -1733,6 +1735,7 @@ end; procedure TRxMemoryData.SortOnFields(const FieldNames: string; CaseInsensitive: Boolean = True; Descending: Boolean = False); begin + SetLength(FAscSortList, 0); CreateIndexList(FieldNames); FCaseInsensitiveSort := CaseInsensitive; FDescendingSort := Descending; @@ -1746,16 +1749,26 @@ end; procedure TRxMemoryData.SortOnFieldsEx(const FieldNames: string; CaseInsensitive: Boolean; Asc: array of boolean); +var + i: Integer; begin -(* CreateIndexList(FieldNames); + FDescendingSort := false; + SetLength(FAscSortList, Length(Asc)); + if Length(Asc)>0 then + begin + for i:=0 to Length(Asc)-1 do + FAscSortList[i]:=Asc[i]; + end; + + CreateIndexList(FieldNames); FCaseInsensitiveSort := CaseInsensitive; - FDescendingSort := Descending; try Sort; except FreeIndexList; raise; - end; *) + end; + SetLength(FAscSortList, 0); end; procedure TRxMemoryData.Sort; @@ -1815,22 +1828,39 @@ var I: Integer; begin Result := 0; - if FIndexList <> nil then begin - for I := 0 to FIndexList.Count - 1 do begin + if FIndexList <> nil then + begin + for I := 0 to FIndexList.Count - 1 do + begin F := TField(FIndexList[I]); Data1 := FindFieldData(Item1.Data, F); - if Data1 <> nil then begin + if Data1 <> nil then + begin Data2 := FindFieldData(Item2.Data, F); - if Data2 <> nil then begin - if Boolean(Data1[0]) and Boolean(Data2[0]) then begin + if Data2 <> nil then + begin + if Boolean(Data1[0]) and Boolean(Data2[0]) then + begin Inc(Data1); Inc(Data2); - Result := CompareFields(Data1, Data2, F.DataType, - FCaseInsensitiveSort); + Result := CompareFields(Data1, Data2, F.DataType, FCaseInsensitiveSort); end - else if Boolean(Data1[0]) then Result := 1 - else if Boolean(Data2[0]) then Result := -1; - if FDescendingSort then Result := -Result; + else + if Boolean(Data1[0]) then + Result := 1 + else + if Boolean(Data2[0]) then + Result := -1; + + if (Length(FAscSortList)>0) then + begin + if I 0 then Exit; diff --git a/components/rx/trunk/rxdb/rxsortmemds.pas b/components/rx/trunk/rxdb/rxsortmemds.pas index 7dde9a1e6..a93cfa186 100644 --- a/components/rx/trunk/rxdb/rxsortmemds.pas +++ b/components/rx/trunk/rxdb/rxsortmemds.pas @@ -63,7 +63,7 @@ procedure TRxMemoryDataSortEngine.SortList(ListField: string; ADataSet: TDataSet; Asc: array of boolean; SortOptions: TRxSortEngineOptions); begin if Assigned(ADataSet) then - (ADataSet as TRxMemoryData).SortOnFields(ListField, seoCaseInsensitiveSort in SortOptions, Asc[0]); + (ADataSet as TRxMemoryData).SortOnFieldsEx(ListField, seoCaseInsensitiveSort in SortOptions, Asc); end; initialization