From b1827f8951b7a7b1dec0b9921a83e8b2cbab8dc4 Mon Sep 17 00:00:00 2001 From: alexs75 Date: Mon, 17 Sep 2012 10:07:41 +0000 Subject: [PATCH] in rxdbgrid in filter and sort form show ColumnCaption for user choise git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@2513 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- components/rx/Demos/RxDBGrid/RxDBGridDemo.lpi | 196 ++++++++--- components/rx/rxdbgrid.pas | 12 +- components/rx/rxfilterby.lfm | 196 +++++------ components/rx/rxfilterby.pas | 305 +++++++++--------- components/rx/rxnew.lpk | 10 +- components/rx/rxnew.pas | 2 +- components/rx/rxsortby.lfm | 155 +++++---- components/rx/rxsortby.pas | 108 +++---- 8 files changed, 554 insertions(+), 430 deletions(-) diff --git a/components/rx/Demos/RxDBGrid/RxDBGridDemo.lpi b/components/rx/Demos/RxDBGrid/RxDBGridDemo.lpi index 4c1abda02..952a5d571 100644 --- a/components/rx/Demos/RxDBGrid/RxDBGridDemo.lpi +++ b/components/rx/Demos/RxDBGrid/RxDBGridDemo.lpi @@ -54,16 +54,16 @@ - + - + - + @@ -77,7 +77,7 @@ - + @@ -501,9 +501,9 @@ - - - + + + @@ -553,11 +553,11 @@ - + - - - + + + @@ -570,12 +570,10 @@ - - - + @@ -591,64 +589,180 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - + - - + + - - + + - + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/components/rx/rxdbgrid.pas b/components/rx/rxdbgrid.pas index 3ce18db2c..499e2f3b4 100644 --- a/components/rx/rxdbgrid.pas +++ b/components/rx/rxdbgrid.pas @@ -421,8 +421,7 @@ type FSortingNow:Boolean; FInProcessCalc: integer; FAllowedOperations: TRxDBGridAllowedOperations; - //FFooterColor: TColor; - //FFooterRowCount: integer; + // FKeyStrokes: TRxDBGridKeyStrokes; FOnGetCellProps: TGetCellPropsEvent; FOptionsRx: TOptionsRx; @@ -436,6 +435,7 @@ type FSortOrder: TSortMarker; FSortEngine: TRxDBGridSortEngine; FPressedCol: TColumn; + // FPressed: boolean; FSwapButtons: boolean; FTracking: boolean; @@ -2594,6 +2594,10 @@ begin FSortEngine.Sort(FSortField, DataSource.DataSet, FSortOrder = smUp, SortEngineOptions); FSortingNow:=false; + + F_SortListField.Clear; + if Assigned(FSortField) then + F_SortListField.Add(FSortField.FieldName); end else HeaderClick(True, ACol); @@ -3398,7 +3402,7 @@ begin OptionsRx := OptionsRx - [rdgFilter]; rxFilterByForm := TrxFilterByForm.Create(Application); NewFilter := DataSource.DataSet.Filter; - if rxFilterByForm.Execute(DataSource.DataSet, NewFilter, F_LastFilter) then + if rxFilterByForm.Execute(Self, NewFilter, F_LastFilter) then begin if NewFilter <> '' then begin @@ -3473,7 +3477,7 @@ begin rxSortByForm := TrxSortByForm.Create(Application); rxSortByForm.CheckBox1.Checked := rdgCaseInsensitiveSort in FOptionsRx; o := not (FSortOrder = smDown); - if rxSortByForm.Execute(DataSource.DataSet, F_SortListField, o) then + if rxSortByForm.Execute(Self, F_SortListField, o) then begin for i := 0 to F_SortListField.Count - 1 do begin diff --git a/components/rx/rxfilterby.lfm b/components/rx/rxfilterby.lfm index a7938170e..c0e5f1558 100644 --- a/components/rx/rxfilterby.lfm +++ b/components/rx/rxfilterby.lfm @@ -9,14 +9,14 @@ object rxFilterByForm: TrxFilterByForm ClientWidth = 644 OnCreate = FormCreate Position = poScreenCenter - LCLVersion = '0.9.31' + LCLVersion = '1.1' object Label1: TLabel AnchorSideLeft.Control = Owner AnchorSideTop.Control = Owner Left = 6 - Height = 18 + Height = 15 Top = 6 - Width = 235 + Width = 234 BorderSpacing.Around = 6 Caption = 'Select filter expression for data' Font.Style = [fsBold] @@ -28,9 +28,9 @@ object rxFilterByForm: TrxFilterByForm AnchorSideTop.Control = Label1 AnchorSideTop.Side = asrBottom Left = 6 - Height = 18 - Top = 30 - Width = 63 + Height = 15 + Top = 27 + Width = 62 BorderSpacing.Around = 6 Caption = 'On field:' Font.Color = clRed @@ -42,9 +42,9 @@ object rxFilterByForm: TrxFilterByForm AnchorSideTop.Control = Label1 AnchorSideTop.Side = asrBottom Left = 168 - Height = 18 - Top = 30 - Width = 84 + Height = 15 + Top = 27 + Width = 83 BorderSpacing.Around = 6 Caption = 'Operation :' Font.Color = clRed @@ -56,9 +56,9 @@ object rxFilterByForm: TrxFilterByForm AnchorSideTop.Control = Label1 AnchorSideTop.Side = asrBottom Left = 271 - Height = 18 - Top = 30 - Width = 89 + Height = 15 + Top = 27 + Width = 88 BorderSpacing.Around = 6 Caption = 'Conditions :' Font.Color = clRed @@ -71,9 +71,9 @@ object rxFilterByForm: TrxFilterByForm AnchorSideTop.Control = Label1 AnchorSideTop.Side = asrBottom Left = 533 - Height = 18 - Top = 30 - Width = 75 + Height = 15 + Top = 27 + Width = 74 BorderSpacing.Around = 6 Caption = 'Operand :' Font.Color = clRed @@ -87,9 +87,9 @@ object rxFilterByForm: TrxFilterByForm AnchorSideBottom.Control = ComboBox25 AnchorSideBottom.Side = asrBottom Left = 527 - Height = 18 - Top = 343 - Width = 34 + Height = 15 + Top = 358 + Width = 33 Anchors = [akLeft, akBottom] Caption = 'End.' Font.Color = clRed @@ -102,8 +102,8 @@ object rxFilterByForm: TrxFilterByForm AnchorSideTop.Control = Label2 AnchorSideTop.Side = asrBottom Left = 6 - Height = 27 - Top = 54 + Height = 29 + Top = 48 Width = 153 BorderSpacing.Around = 6 ItemHeight = 0 @@ -114,8 +114,8 @@ object rxFilterByForm: TrxFilterByForm AnchorSideTop.Control = Label2 AnchorSideTop.Side = asrBottom Left = 168 - Height = 27 - Top = 54 + Height = 29 + Top = 48 Width = 96 BorderSpacing.Around = 6 DropDownCount = 9 @@ -129,8 +129,8 @@ object rxFilterByForm: TrxFilterByForm AnchorSideTop.Side = asrBottom AnchorSideRight.Control = ComboBox3 Left = 271 - Height = 23 - Top = 54 + Height = 25 + Top = 48 Width = 250 Anchors = [akTop, akLeft, akRight] BorderSpacing.Around = 6 @@ -143,8 +143,8 @@ object rxFilterByForm: TrxFilterByForm AnchorSideRight.Control = Owner AnchorSideRight.Side = asrBottom Left = 527 - Height = 27 - Top = 54 + Height = 29 + Top = 48 Width = 111 Anchors = [akTop, akRight] BorderSpacing.Around = 6 @@ -163,8 +163,8 @@ object rxFilterByForm: TrxFilterByForm AnchorSideRight.Control = ComboBox1 AnchorSideRight.Side = asrBottom Left = 8 - Height = 27 - Top = 89 + Height = 29 + Top = 85 Width = 149 Anchors = [akTop, akLeft, akRight] BorderSpacing.Left = 6 @@ -181,8 +181,8 @@ object rxFilterByForm: TrxFilterByForm AnchorSideRight.Control = ComboBox2 AnchorSideRight.Side = asrBottom Left = 168 - Height = 27 - Top = 87 + Height = 29 + Top = 83 Width = 96 Anchors = [akTop, akLeft, akRight] BorderSpacing.Top = 6 @@ -199,8 +199,8 @@ object rxFilterByForm: TrxFilterByForm AnchorSideTop.Side = asrBottom AnchorSideRight.Control = ComboBox3 Left = 270 - Height = 23 - Top = 87 + Height = 25 + Top = 83 Width = 251 Anchors = [akTop, akLeft, akRight] BorderSpacing.Left = 6 @@ -214,8 +214,8 @@ object rxFilterByForm: TrxFilterByForm AnchorSideRight.Control = Owner AnchorSideRight.Side = asrBottom Left = 527 - Height = 27 - Top = 87 + Height = 29 + Top = 83 Width = 111 Anchors = [akTop, akRight] BorderSpacing.Around = 6 @@ -234,8 +234,8 @@ object rxFilterByForm: TrxFilterByForm AnchorSideRight.Control = ComboBox1 AnchorSideRight.Side = asrBottom Left = 8 - Height = 27 - Top = 124 + Height = 29 + Top = 122 Width = 149 Anchors = [akTop, akLeft, akRight] BorderSpacing.Left = 6 @@ -252,8 +252,8 @@ object rxFilterByForm: TrxFilterByForm AnchorSideRight.Control = ComboBox2 AnchorSideRight.Side = asrBottom Left = 168 - Height = 27 - Top = 122 + Height = 29 + Top = 120 Width = 96 Anchors = [akTop, akLeft, akRight] BorderSpacing.Top = 6 @@ -270,8 +270,8 @@ object rxFilterByForm: TrxFilterByForm AnchorSideTop.Side = asrBottom AnchorSideRight.Control = ComboBox3 Left = 270 - Height = 23 - Top = 122 + Height = 25 + Top = 120 Width = 251 Anchors = [akTop, akLeft, akRight] BorderSpacing.Left = 6 @@ -285,8 +285,8 @@ object rxFilterByForm: TrxFilterByForm AnchorSideRight.Control = Owner AnchorSideRight.Side = asrBottom Left = 527 - Height = 27 - Top = 122 + Height = 29 + Top = 120 Width = 111 Anchors = [akTop, akRight] BorderSpacing.Around = 6 @@ -305,7 +305,7 @@ object rxFilterByForm: TrxFilterByForm AnchorSideRight.Control = ComboBox1 AnchorSideRight.Side = asrBottom Left = 8 - Height = 27 + Height = 29 Top = 159 Width = 149 Anchors = [akTop, akLeft, akRight] @@ -323,7 +323,7 @@ object rxFilterByForm: TrxFilterByForm AnchorSideRight.Control = ComboBox2 AnchorSideRight.Side = asrBottom Left = 168 - Height = 27 + Height = 29 Top = 157 Width = 96 Anchors = [akTop, akLeft, akRight] @@ -341,7 +341,7 @@ object rxFilterByForm: TrxFilterByForm AnchorSideTop.Side = asrBottom AnchorSideRight.Control = ComboBox3 Left = 270 - Height = 23 + Height = 25 Top = 157 Width = 251 Anchors = [akTop, akLeft, akRight] @@ -356,7 +356,7 @@ object rxFilterByForm: TrxFilterByForm AnchorSideRight.Control = Owner AnchorSideRight.Side = asrBottom Left = 527 - Height = 27 + Height = 29 Top = 157 Width = 111 Anchors = [akTop, akRight] @@ -376,8 +376,8 @@ object rxFilterByForm: TrxFilterByForm AnchorSideRight.Control = ComboBox1 AnchorSideRight.Side = asrBottom Left = 8 - Height = 27 - Top = 194 + Height = 29 + Top = 196 Width = 149 Anchors = [akTop, akLeft, akRight] BorderSpacing.Left = 6 @@ -394,8 +394,8 @@ object rxFilterByForm: TrxFilterByForm AnchorSideRight.Control = ComboBox2 AnchorSideRight.Side = asrBottom Left = 168 - Height = 27 - Top = 192 + Height = 29 + Top = 194 Width = 96 Anchors = [akTop, akLeft, akRight] BorderSpacing.Top = 6 @@ -412,8 +412,8 @@ object rxFilterByForm: TrxFilterByForm AnchorSideTop.Side = asrBottom AnchorSideRight.Control = ComboBox3 Left = 270 - Height = 23 - Top = 192 + Height = 25 + Top = 194 Width = 251 Anchors = [akTop, akLeft, akRight] BorderSpacing.Left = 6 @@ -427,8 +427,8 @@ object rxFilterByForm: TrxFilterByForm AnchorSideRight.Control = Owner AnchorSideRight.Side = asrBottom Left = 527 - Height = 27 - Top = 192 + Height = 29 + Top = 194 Width = 111 Anchors = [akTop, akRight] BorderSpacing.Around = 6 @@ -447,8 +447,8 @@ object rxFilterByForm: TrxFilterByForm AnchorSideRight.Control = ComboBox1 AnchorSideRight.Side = asrBottom Left = 8 - Height = 27 - Top = 229 + Height = 29 + Top = 233 Width = 149 Anchors = [akTop, akLeft, akRight] BorderSpacing.Left = 6 @@ -465,8 +465,8 @@ object rxFilterByForm: TrxFilterByForm AnchorSideRight.Control = ComboBox2 AnchorSideRight.Side = asrBottom Left = 168 - Height = 27 - Top = 227 + Height = 29 + Top = 231 Width = 96 Anchors = [akTop, akLeft, akRight] BorderSpacing.Top = 6 @@ -483,8 +483,8 @@ object rxFilterByForm: TrxFilterByForm AnchorSideTop.Side = asrBottom AnchorSideRight.Control = ComboBox3 Left = 270 - Height = 23 - Top = 227 + Height = 25 + Top = 231 Width = 251 Anchors = [akTop, akLeft, akRight] BorderSpacing.Left = 6 @@ -498,8 +498,8 @@ object rxFilterByForm: TrxFilterByForm AnchorSideRight.Control = Owner AnchorSideRight.Side = asrBottom Left = 527 - Height = 27 - Top = 227 + Height = 29 + Top = 231 Width = 111 Anchors = [akTop, akRight] BorderSpacing.Around = 6 @@ -518,8 +518,8 @@ object rxFilterByForm: TrxFilterByForm AnchorSideRight.Control = ComboBox1 AnchorSideRight.Side = asrBottom Left = 8 - Height = 27 - Top = 264 + Height = 29 + Top = 270 Width = 149 Anchors = [akTop, akLeft, akRight] BorderSpacing.Left = 6 @@ -536,8 +536,8 @@ object rxFilterByForm: TrxFilterByForm AnchorSideRight.Control = ComboBox2 AnchorSideRight.Side = asrBottom Left = 168 - Height = 27 - Top = 262 + Height = 29 + Top = 268 Width = 96 Anchors = [akTop, akLeft, akRight] BorderSpacing.Top = 6 @@ -554,8 +554,8 @@ object rxFilterByForm: TrxFilterByForm AnchorSideTop.Side = asrBottom AnchorSideRight.Control = ComboBox3 Left = 270 - Height = 23 - Top = 262 + Height = 25 + Top = 268 Width = 251 Anchors = [akTop, akLeft, akRight] BorderSpacing.Left = 6 @@ -569,8 +569,8 @@ object rxFilterByForm: TrxFilterByForm AnchorSideRight.Control = Owner AnchorSideRight.Side = asrBottom Left = 527 - Height = 27 - Top = 262 + Height = 29 + Top = 268 Width = 111 Anchors = [akTop, akRight] BorderSpacing.Around = 6 @@ -589,8 +589,8 @@ object rxFilterByForm: TrxFilterByForm AnchorSideRight.Control = ComboBox1 AnchorSideRight.Side = asrBottom Left = 8 - Height = 27 - Top = 299 + Height = 29 + Top = 307 Width = 149 Anchors = [akTop, akLeft, akRight] BorderSpacing.Left = 6 @@ -607,8 +607,8 @@ object rxFilterByForm: TrxFilterByForm AnchorSideRight.Control = ComboBox2 AnchorSideRight.Side = asrBottom Left = 168 - Height = 27 - Top = 297 + Height = 29 + Top = 305 Width = 96 Anchors = [akTop, akLeft, akRight] BorderSpacing.Top = 6 @@ -625,8 +625,8 @@ object rxFilterByForm: TrxFilterByForm AnchorSideTop.Side = asrBottom AnchorSideRight.Control = ComboBox3 Left = 270 - Height = 23 - Top = 297 + Height = 25 + Top = 305 Width = 251 Anchors = [akTop, akLeft, akRight] BorderSpacing.Left = 6 @@ -640,8 +640,8 @@ object rxFilterByForm: TrxFilterByForm AnchorSideRight.Control = Owner AnchorSideRight.Side = asrBottom Left = 527 - Height = 27 - Top = 297 + Height = 29 + Top = 305 Width = 111 Anchors = [akTop, akRight] BorderSpacing.Around = 6 @@ -660,8 +660,8 @@ object rxFilterByForm: TrxFilterByForm AnchorSideRight.Control = ComboBox1 AnchorSideRight.Side = asrBottom Left = 8 - Height = 27 - Top = 334 + Height = 29 + Top = 344 Width = 149 Anchors = [akTop, akLeft, akRight] BorderSpacing.Left = 6 @@ -678,8 +678,8 @@ object rxFilterByForm: TrxFilterByForm AnchorSideRight.Control = ComboBox2 AnchorSideRight.Side = asrBottom Left = 168 - Height = 27 - Top = 332 + Height = 29 + Top = 342 Width = 96 Anchors = [akTop, akLeft, akRight] BorderSpacing.Top = 6 @@ -696,8 +696,8 @@ object rxFilterByForm: TrxFilterByForm AnchorSideTop.Side = asrBottom AnchorSideRight.Control = ComboBox3 Left = 270 - Height = 23 - Top = 332 + Height = 25 + Top = 342 Width = 251 Anchors = [akTop, akLeft, akRight] BorderSpacing.Left = 6 @@ -710,8 +710,8 @@ object rxFilterByForm: TrxFilterByForm AnchorSideBottom.Control = Owner AnchorSideBottom.Side = asrBottom Left = 6 - Height = 27 - Top = 412 + Height = 29 + Top = 410 Width = 58 Anchors = [akLeft, akBottom] BorderSpacing.Around = 6 @@ -729,10 +729,10 @@ object rxFilterByForm: TrxFilterByForm AnchorSideRight.Side = asrBottom AnchorSideBottom.Control = Owner AnchorSideBottom.Side = asrBottom - Left = 597 - Height = 23 - Top = 416 - Width = 41 + Left = 592 + Height = 27 + Top = 412 + Width = 46 Anchors = [akRight, akBottom] AutoSize = True BorderSpacing.Around = 6 @@ -745,10 +745,10 @@ object rxFilterByForm: TrxFilterByForm AnchorSideRight.Control = Button1 AnchorSideBottom.Control = Owner AnchorSideBottom.Side = asrBottom - Left = 542 - Height = 23 - Top = 416 - Width = 49 + Left = 533 + Height = 27 + Top = 412 + Width = 53 Anchors = [akRight, akBottom] AutoSize = True BorderSpacing.Around = 6 @@ -761,10 +761,10 @@ object rxFilterByForm: TrxFilterByForm AnchorSideRight.Control = Button2 AnchorSideBottom.Control = Owner AnchorSideBottom.Side = asrBottom - Left = 465 - Height = 23 - Top = 416 - Width = 71 + Left = 452 + Height = 27 + Top = 412 + Width = 75 Anchors = [akRight, akBottom] AutoSize = True BorderSpacing.Around = 6 diff --git a/components/rx/rxfilterby.pas b/components/rx/rxfilterby.pas index 5d53ca96a..ebffc9999 100644 --- a/components/rx/rxfilterby.pas +++ b/components/rx/rxfilterby.pas @@ -36,8 +36,8 @@ unit rxfilterby; interface uses - Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs, - StdCtrls, db; + Classes, SysUtils, FileUtil, rxdbgrid, LResources, Forms, Controls, Graphics, + Dialogs, StdCtrls, db; type @@ -100,19 +100,20 @@ type Combo_2 : Array[1..9] of TComboBox; Edit_1 : Array[1..9] of TEdit; Combo_3 : Array[1..9] of TComboBox; - Table : TDataSet; - procedure ClearALL(adoTable : TDataSet); + + FGrid : TRxDBGrid; + procedure ClearALL(AGrid : TRxDBGrid); function FindCombo(CB:TComboBox):Integer; function FindEdit(ED:TEdit):Integer; public - function Execute(adoTable : TDataSet; Var FilterStr : String; Var LastFilter : TstringList):Boolean; + function Execute(AGrid : TRxDBGrid; var FilterStr : String; var LastFilter : TstringList):Boolean; end; var rxFilterByForm: TrxFilterByForm; implementation -uses rxdconst; +uses rxdconst, rxstrutils, DBGrids; {$R *.lfm} @@ -120,12 +121,12 @@ uses rxdconst; procedure TrxFilterByForm.Button2Click(Sender: TObject); begin - ModalResult := mrCancel; + ModalResult := mrCancel; end; procedure TrxFilterByForm.Button3Click(Sender: TObject); begin - ClearALL(Table); + ClearALL(FGrid); end; procedure TrxFilterByForm.ComboBoxChange(Sender: TObject); @@ -178,24 +179,25 @@ begin ModalResult := mrOK; end; -procedure TrxFilterByForm.ClearALL(adoTable : TDataSet); +procedure TrxFilterByForm.ClearALL(AGrid: TRxDBGrid); var - X : Integer; + i : Integer; begin //***************************************************************************** Combo_1[1].Items.Clear; Combo_1[1].Items.Add(''); - For X := 0 To adoTable.FieldCount-1 do - Begin - if (adoTable.Fields[X].FieldKind=fkData) And (adoTable.Fields[X].Visible) Then - Combo_1[1].Items.Add(adoTable.Fields[X].FieldName); - End; + for i := 0 To AGrid.Columns.Count-1 do + begin + if (AGrid.Columns[i].Field.FieldKind=fkData) and (AGrid.Columns[i].Visible) then + Combo_1[1].Items.Objects[Combo_1[1].Items.Add(AGrid.Columns[i].Title.Caption)]:=AGrid.Columns[i].Field; + end; + Combo_1[1].ItemIndex := 0; - For X := 2 To 9 do - Begin - Combo_1[X].Items.Assign(Combo_1[1].Items); - Combo_1[X].ItemIndex := 0; - End; + for i := 2 To 9 do + Begin + Combo_1[i].Items.Assign(Combo_1[1].Items); + Combo_1[i].ItemIndex := 0; + End; Combo_2[1].Items.Clear; Combo_2[1].Items.Add(' = '); @@ -208,155 +210,160 @@ begin Combo_2[1].Items.Add(' IS NULL '); Combo_2[1].Items.Add(' IS NOT NULL '); Combo_2[1].ItemIndex := 0; - for X := 2 To 9 do + for i := 2 To 9 do begin - Combo_2[X].Items.Assign(Combo_2[1].Items); - Combo_2[X].ItemIndex := 0; + Combo_2[i].Items.Assign(Combo_2[1].Items); + Combo_2[i].ItemIndex := 0; end; - for X := 1 To 9 do + for i := 1 To 9 do begin - Combo_3[X].ItemIndex := 0; + Combo_3[i].ItemIndex := 0; end; - for X := 1 To 9 do Edit_1[X].Text := ''; + for i := 1 To 9 do Edit_1[i].Text := ''; //***************************************************************************** end; -function TrxFilterByForm.Execute(adoTable : TDataSet; Var FilterStr : String; Var LastFilter : TstringList):Boolean; +function TrxFilterByForm.Execute(AGrid: TRxDBGrid; var FilterStr: String; + var LastFilter: TstringList): Boolean; Var X : Integer; P : Integer; - S : String; + S, S1 : String; SD : String; - FF : TField; + C : TColumn; Begin - Result := False; - //***************************************************************************** - Combo_1[1]:= ComboBox1; - Combo_1[2]:= ComboBox4; - Combo_1[3]:= ComboBox7; - Combo_1[4]:= ComboBox10; - Combo_1[5]:= ComboBox13; - Combo_1[6]:= ComboBox16; - Combo_1[7]:= ComboBox19; - Combo_1[8]:= ComboBox22; - Combo_1[9]:= ComboBox25; + Result := False; + //***************************************************************************** + Combo_1[1]:= ComboBox1; + Combo_1[2]:= ComboBox4; + Combo_1[3]:= ComboBox7; + Combo_1[4]:= ComboBox10; + Combo_1[5]:= ComboBox13; + Combo_1[6]:= ComboBox16; + Combo_1[7]:= ComboBox19; + Combo_1[8]:= ComboBox22; + Combo_1[9]:= ComboBox25; - Combo_2[1]:= ComboBox2; - Combo_2[2]:= ComboBox5; - Combo_2[3]:= ComboBox8; - Combo_2[4]:= ComboBox11; - Combo_2[5]:= ComboBox14; - Combo_2[6]:= ComboBox17; - Combo_2[7]:= ComboBox20; - Combo_2[8]:= ComboBox23; - Combo_2[9]:= ComboBox26; + Combo_2[1]:= ComboBox2; + Combo_2[2]:= ComboBox5; + Combo_2[3]:= ComboBox8; + Combo_2[4]:= ComboBox11; + Combo_2[5]:= ComboBox14; + Combo_2[6]:= ComboBox17; + Combo_2[7]:= ComboBox20; + Combo_2[8]:= ComboBox23; + Combo_2[9]:= ComboBox26; - Combo_3[1]:= ComboBox3; - Combo_3[2]:= ComboBox6; - Combo_3[3]:= ComboBox9; - Combo_3[4]:= ComboBox12; - Combo_3[5]:= ComboBox15; - Combo_3[6]:= ComboBox18; - Combo_3[7]:= ComboBox21; - Combo_3[8]:= ComboBox24; - Combo_3[9]:= ComboBox27; - Combo_3[9].Visible := False; + Combo_3[1]:= ComboBox3; + Combo_3[2]:= ComboBox6; + Combo_3[3]:= ComboBox9; + Combo_3[4]:= ComboBox12; + Combo_3[5]:= ComboBox15; + Combo_3[6]:= ComboBox18; + Combo_3[7]:= ComboBox21; + Combo_3[8]:= ComboBox24; + Combo_3[9]:= ComboBox27; + Combo_3[9].Visible := False; - Edit_1[1] := Edit1; - Edit_1[2] := Edit2; - Edit_1[3] := Edit3; - Edit_1[4] := Edit4; - Edit_1[5] := Edit5; - Edit_1[6] := Edit6; - Edit_1[7] := Edit7; - Edit_1[8] := Edit8; - Edit_1[9] := Edit9; + Edit_1[1] := Edit1; + Edit_1[2] := Edit2; + Edit_1[3] := Edit3; + Edit_1[4] := Edit4; + Edit_1[5] := Edit5; + Edit_1[6] := Edit6; + Edit_1[7] := Edit7; + Edit_1[8] := Edit8; + Edit_1[9] := Edit9; //***************************************************************************** - Table := adoTable; - ClearALL(Table); - if LastFilter.Count > 0 Then - Begin - For X := 0 To LastFilter.Count-1 do - Begin - S := LastFilter.Strings[X]; - P := Pos('|||',S); - if P > 0 Then - Begin - Combo_1[X+1].ItemIndex := Combo_1[X+1].Items.IndexOf(System.Copy(S,1,P-1)); - System.Delete(S,1,P+2); - End; - P := Pos('|||',S); - if P > 0 Then - Begin - SD:=System.Copy(S,1,P-1); - Combo_2[X+1].ItemIndex := Combo_2[X+1].Items.IndexOf(System.Copy(S,1,P-1)); - System.Delete(S,1,P+2); - if (SD=' IS NULL ') or (SD=' IS NOT NULL ') Then - Begin - Edit_1[X+1].Text := ''; - Edit_1[X+1].Enabled := False; - Edit_1[X+1].Color := clInactiveCaption; - End; - End; - P := Pos('|||',S); - if P > 0 Then - Begin - Edit_1[X+1].Text := System.Copy(S,1,P-1); - System.Delete(S,1,P+2); - End; - Combo_3[X+1].ItemIndex := Combo_3[X+1].Items.IndexOf(S); - if Combo_3[X+1].ItemIndex = -1 Then Combo_3[X+1].ItemIndex := 0; - End; - End; + FGrid := AGrid; + ClearALL(FGrid); + if LastFilter.Count > 0 Then + begin + for X := 0 To LastFilter.Count-1 do + begin + S := LastFilter.Strings[X]; + P := Pos('|||',S); + if P > 0 Then + begin + S1:=System.Copy(S,1,P-1); + C:=FGrid.ColumnByFieldName(S1); + Combo_1[X+1].ItemIndex := Combo_1[X+1].Items.IndexOf(C.Title.Caption); + System.Delete(S,1,P+2); + end; - ShowModal; - if ModalResult=mrOK Then - Begin - Result := True; - FilterStr := ''; - LastFilter.Clear; - For X := 1 to 9 Do - Begin - if (Combo_1[X].Text <> '') - And (Combo_2[X].Text <> '') Then - Begin - if (Edit_1[X].Enabled=False) or (Edit_1[X].Text <> '') Then - Begin - if X>1 Then - FilterStr := FilterStr+Combo_3[X-1].Text+' '; - FF := Table.FindField(Combo_1[X].Text); - Case FF.DataType of - ftDateTime , - ftDate : FilterStr := FilterStr+'('+Combo_1[X].Text+Combo_2[X].Text+Char(39)+Copy(Edit_1[X].Text,7,4)+Copy(Edit_1[X].Text,3,4)+Copy(Edit_1[X].Text,1,2)+Copy(Edit_1[X].Text,11,9)+Char(39)+') '; - ftUnknown : FilterStr := FilterStr+'('+Combo_1[X].Text+Combo_2[X].Text+Edit_1[X].Text+') '; - ftTime, - ftString, - ftMemo : FilterStr := FilterStr+'('+Combo_1[X].Text+Combo_2[X].Text+Char(39)+Edit_1[X].Text+Char(39)+') '; - else - FilterStr := FilterStr+'('+Combo_1[X].Text+Combo_2[X].Text+Edit_1[X].Text+') '; - End; - LastFilter.Add(Combo_1[X].Text+'|||'+Combo_2[X].Text+'|||'+Edit_1[X].Text+'|||'+Combo_3[X].Text); - End; - End; - End; - End; -End; + P := Pos('|||',S); + if P > 0 Then + begin + SD:=System.Copy(S,1,P-1); + Combo_2[X+1].ItemIndex := Combo_2[X+1].Items.IndexOf(System.Copy(S,1,P-1)); + System.Delete(S,1,P+2); + if (SD=' IS NULL ') or (SD=' IS NOT NULL ') Then + Begin + Edit_1[X+1].Text:= ''; + Edit_1[X+1].Enabled := False; + Edit_1[X+1].Color := clInactiveCaption; + End; + end; + + P := Pos('|||',S); + if P > 0 then + begin + Edit_1[X+1].Text := System.Copy(S,1,P-1); + System.Delete(S,1,P+2); + end; + Combo_3[X+1].ItemIndex := Combo_3[X+1].Items.IndexOf(S); + + if Combo_3[X+1].ItemIndex = -1 Then Combo_3[X+1].ItemIndex := 0; + end; + end; + + if ShowModal = mrOK Then + begin + Result := True; + FilterStr := ''; + LastFilter.Clear; + for X := 1 to 9 Do + begin + if (Combo_1[X].Text <> '') and (Combo_2[X].Text <> '') then + begin + if (Edit_1[X].Enabled=False) or (Edit_1[X].Text <> '') Then + begin + if X>1 Then + FilterStr := FilterStr+Combo_3[X-1].Text+' '; + + C:=FGrid.ColumnByCaption(Combo_1[X].Text); + case C.Field.DataType of + ftDateTime , + ftDate : FilterStr := FilterStr+'('+C.FieldName+Combo_2[X].Text+Char(39)+Copy(Edit_1[X].Text,7,4)+Copy(Edit_1[X].Text,3,4)+Copy(Edit_1[X].Text,1,2)+Copy(Edit_1[X].Text,11,9)+Char(39)+') '; + ftUnknown : FilterStr := FilterStr+'('+C.FieldName+Combo_2[X].Text+Edit_1[X].Text+') '; + ftTime, + ftString, + ftMemo : FilterStr := FilterStr+'('+C.FieldName+Combo_2[X].Text+QuotedString(Edit_1[X].Text, '''')+') '; + else + FilterStr := FilterStr+'('+C.FieldName+Combo_2[X].Text+Edit_1[X].Text+') '; + end; + LastFilter.Add(C.FieldName+'|||'+Combo_2[X].Text+'|||'+Edit_1[X].Text+'|||'+Combo_3[X].Text); + end; + end; + end; + end; +end; Function TrxFilterByForm.FindCombo(CB:TComboBox):Integer; -Var - X : Integer; -Begin - Result :=0; - For X := 1 to 9 do - Begin - if Combo_2[X]=CB Then - Begin - Result := X; - Exit; - End; - End; -End; +var + X : Integer; +begin + Result :=0; + for X := 1 to 9 do + begin + if Combo_2[X]=CB Then + begin + Result := X; + Exit; + end; + end; +end; function TrxFilterByForm.FindEdit(ED:TEdit):Integer; var diff --git a/components/rx/rxnew.lpk b/components/rx/rxnew.lpk index 6f9c43ba7..534400c6f 100644 --- a/components/rx/rxnew.lpk +++ b/components/rx/rxnew.lpk @@ -27,7 +27,7 @@ translate to Lazarus by alexs in 2005 - 2012 "/> - + @@ -287,6 +287,14 @@ translate to Lazarus by alexs in 2005 - 2012 + + + + + + + + diff --git a/components/rx/rxnew.pas b/components/rx/rxnew.pas index c2d061fd1..dedb26152 100644 --- a/components/rx/rxnew.pas +++ b/components/rx/rxnew.pas @@ -18,7 +18,7 @@ uses RxSystemServices, rxtbrsetup, RxTimeEdit, rxtoolbar, RxVersInfo, RxViewsPanel, rxxpman, seldsfrm, tooledit, vclutils, RxCloseFormValidator, RxHistoryNavigator, ex_rx_bin_datapacket, ex_rx_datapacket, - ex_rx_xml_datapacket, LazarusPackageIntf; + ex_rx_xml_datapacket, rxsortby, LazarusPackageIntf; implementation diff --git a/components/rx/rxsortby.lfm b/components/rx/rxsortby.lfm index aa3deb385..c77072ac4 100644 --- a/components/rx/rxsortby.lfm +++ b/components/rx/rxsortby.lfm @@ -7,30 +7,29 @@ object rxSortByForm: TrxSortByForm Caption = 'Sort by fields' ClientHeight = 411 ClientWidth = 684 - OnClose = FormClose OnCreate = FormCreate Position = poScreenCenter - LCLVersion = '0.9.31' + LCLVersion = '1.1' object Label1: TLabel - AnchorSideLeft.Control = Owner + AnchorSideLeft.Control = AddBtn + AnchorSideLeft.Side = asrBottom AnchorSideTop.Control = Owner - Left = 6 - Height = 18 + Left = 417 + Height = 15 Top = 6 - Width = 109 + Width = 105 BorderSpacing.Around = 6 Caption = '&Fields for sorting:' FocusControl = ListBox1 ParentColor = False end object Label2: TLabel - AnchorSideLeft.Control = AddBtn - AnchorSideLeft.Side = asrBottom + AnchorSideLeft.Control = Owner AnchorSideTop.Control = Owner - Left = 415 - Height = 18 + Left = 6 + Height = 15 Top = 6 - Width = 57 + Width = 55 BorderSpacing.Around = 6 Caption = '&All fields:' FocusControl = ListBox2 @@ -41,9 +40,9 @@ object rxSortByForm: TrxSortByForm AnchorSideBottom.Control = ComboBox1 AnchorSideBottom.Side = asrBottom Left = 6 - Height = 18 - Top = 318 - Width = 108 + Height = 15 + Top = 314 + Width = 104 Anchors = [akLeft, akBottom] BorderSpacing.Left = 6 Caption = 'Select sort order' @@ -51,22 +50,20 @@ object rxSortByForm: TrxSortByForm ParentColor = False end object ListBox2: TListBox - AnchorSideLeft.Control = AddBtn - AnchorSideLeft.Side = asrBottom + AnchorSideLeft.Control = Owner AnchorSideTop.Control = Label2 AnchorSideTop.Side = asrBottom - AnchorSideRight.Control = Owner - AnchorSideRight.Side = asrBottom + AnchorSideRight.Control = AddBtn AnchorSideBottom.Control = ComboBox1 - Left = 415 - Height = 273 - Top = 30 - Width = 263 + Left = 6 + Height = 267 + Top = 27 + Width = 262 Anchors = [akTop, akLeft, akRight, akBottom] BorderSpacing.Around = 6 ItemHeight = 0 OnDblClick = ListBox2DblClick - ScrollWidth = 261 + ScrollWidth = 260 TabOrder = 0 TopIndex = -1 end @@ -76,10 +73,10 @@ object rxSortByForm: TrxSortByForm AnchorSideTop.Side = asrBottom AnchorSideRight.Control = AddBtn AnchorSideRight.Side = asrBottom - Left = 275 - Height = 29 - Top = 65 - Width = 134 + Left = 274 + Height = 35 + Top = 68 + Width = 137 Anchors = [akTop, akLeft, akRight] AutoSize = True BorderSpacing.Top = 6 @@ -89,18 +86,16 @@ object rxSortByForm: TrxSortByForm 0400000000001401000000000000000000001000000010000000000000000000 80000080000000808000800000008000800080800000C0C0C000808080000000 C80000FF000000FFFF00FF000000FF00FF00FFFF0000FFFFFF00777777777777 - 7777777777777777777777877777777777777777777777007777777777777777 - 7777770907777777777777777777770990777777777777777777770999077777 - 7777777777777709999077777777777800000009999907777777777099999999 - 9999907777777770999999999999990777777770999999999999999077777770 - 9999999999999999F7777770999999999999999F7777777099999999999999F7 - 777777709999999999999F7777777778FFFFFF899999F7777777777777777789 - 999F7777777777777777778999F7777777777777777777899F77777777777777 - 77777789F7777777777777777777778F7777777777777777777777F777777777 + 7777777777777777777777777877777777777777777777770077777777777777 + 7777777090777777777777777777770990777777777777777777709990777777 + 7777777777770999907777777777777777709999900000008777777777099999 + 999999990777777770999999999999990777777709999999999999990777777F + 999999999999999907777777F999999999999999077777777F99999999999999 + 0777777777F999999999999907777777777F999998FFFFFF877777777777F999 + 987777777777777777777F999877777777777777777777F99877777777777777 + 7777777F987777777777777777777777F877777777777777777777777F777777 7777777777777777777777777777 } - Layout = blGlyphRight - NumGlyphs = 0 OnClick = RemoveBtnClick TabOrder = 2 end @@ -110,10 +105,10 @@ object rxSortByForm: TrxSortByForm AnchorSideTop.Side = asrBottom AnchorSideRight.Control = AddBtn AnchorSideRight.Side = asrBottom - Left = 275 - Height = 30 - Top = 100 - Width = 134 + Left = 274 + Height = 36 + Top = 109 + Width = 137 Anchors = [akTop, akLeft, akRight] AutoSize = True BorderSpacing.Top = 6 @@ -133,7 +128,6 @@ object rxSortByForm: TrxSortByForm 77777709F7777777777077777777777F77777777777077777777777777777777 7770777777777777777777777770777777777777777777777770 } - NumGlyphs = 0 OnClick = UpBtnClick TabOrder = 3 end @@ -143,10 +137,10 @@ object rxSortByForm: TrxSortByForm AnchorSideTop.Side = asrBottom AnchorSideRight.Control = AddBtn AnchorSideRight.Side = asrBottom - Left = 275 - Height = 30 - Top = 136 - Width = 134 + Left = 274 + Height = 36 + Top = 151 + Width = 137 Anchors = [akTop, akLeft, akRight] AutoSize = True BorderSpacing.Top = 6 @@ -166,7 +160,6 @@ object rxSortByForm: TrxSortByForm 77709999999F7777777077777778000000087777777077777777777777777777 7770777777777777777777777770777777777777777777777770 } - NumGlyphs = 0 OnClick = DownBtnClick TabOrder = 4 end @@ -176,10 +169,10 @@ object rxSortByForm: TrxSortByForm AnchorSideRight.Control = Owner AnchorSideRight.Side = asrBottom AnchorSideBottom.Control = CheckBox1 - Left = 120 - Height = 27 - Top = 309 - Width = 558 + Left = 116 + Height = 29 + Top = 300 + Width = 562 Anchors = [akLeft, akRight, akBottom] BorderSpacing.Around = 6 ItemHeight = 0 @@ -187,20 +180,22 @@ object rxSortByForm: TrxSortByForm TabOrder = 5 end object ListBox1: TListBox - AnchorSideLeft.Control = Owner + AnchorSideLeft.Control = AddBtn + AnchorSideLeft.Side = asrBottom AnchorSideTop.Control = Label1 AnchorSideTop.Side = asrBottom - AnchorSideRight.Control = AddBtn + AnchorSideRight.Control = Owner + AnchorSideRight.Side = asrBottom AnchorSideBottom.Control = ComboBox1 - Left = 6 - Height = 273 - Top = 30 - Width = 263 + Left = 417 + Height = 267 + Top = 27 + Width = 261 Anchors = [akTop, akLeft, akRight, akBottom] BorderSpacing.Around = 6 ItemHeight = 0 OnDblClick = ListBox1DblClick - ScrollWidth = 261 + ScrollWidth = 259 TabOrder = 6 TopIndex = -1 end @@ -208,10 +203,10 @@ object rxSortByForm: TrxSortByForm AnchorSideLeft.Control = Owner AnchorSideLeft.Side = asrCenter AnchorSideTop.Control = ListBox1 - Left = 275 - Height = 29 - Top = 30 - Width = 134 + Left = 274 + Height = 35 + Top = 27 + Width = 137 AutoSize = True Caption = '&Add field to sort' Glyph.Data = { @@ -219,33 +214,33 @@ object rxSortByForm: TrxSortByForm 0400000000001401000000000000000000001000000010000000000000000000 80000080000000808000800000008000800080800000C0C0C000808080000000 C80000FF000000FFFF00FF000000FF00FF00FFFF0000FFFFFF00777777777777 - 7777777777777777777777777877777777777777777777770077777777777777 - 7777777090777777777777777777770990777777777777777777709990777777 - 7777777777770999907777777777777777709999900000008777777777099999 - 999999990777777770999999999999990777777709999999999999990777777F - 999999999999999907777777F999999999999999077777777F99999999999999 - 0777777777F999999999999907777777777F999998FFFFFF877777777777F999 - 987777777777777777777F999877777777777777777777F99877777777777777 - 7777777F987777777777777777777777F877777777777777777777777F777777 + 7777777777777777777777877777777777777777777777007777777777777777 + 7777770907777777777777777777770990777777777777777777770999077777 + 7777777777777709999077777777777800000009999907777777777099999999 + 9999907777777770999999999999990777777770999999999999999077777770 + 9999999999999999F7777770999999999999999F7777777099999999999999F7 + 777777709999999999999F7777777778FFFFFF899999F7777777777777777789 + 999F7777777777777777778999F7777777777777777777899F77777777777777 + 77777789F7777777777777777777778F7777777777777777777777F777777777 7777777777777777777777777777 } - NumGlyphs = 0 + Layout = blGlyphRight OnClick = AddBtnClick TabOrder = 1 end object ButtonPanel1: TButtonPanel Left = 6 - Height = 36 - Top = 369 + Height = 42 + Top = 363 Width = 672 OKButton.Name = 'OKButton' - OKButton.Caption = '&ОК' + OKButton.DefaultCaption = True HelpButton.Name = 'HelpButton' - HelpButton.Caption = '&Справка' + HelpButton.DefaultCaption = True CloseButton.Name = 'CloseButton' - CloseButton.Caption = '&Закрыть' + CloseButton.DefaultCaption = True CancelButton.Name = 'CancelButton' - CancelButton.Caption = 'Отмена' + CancelButton.DefaultCaption = True TabOrder = 7 ShowButtons = [pbOK, pbCancel, pbHelp] end @@ -255,9 +250,9 @@ object rxSortByForm: TrxSortByForm AnchorSideTop.Side = asrBottom AnchorSideBottom.Control = ButtonPanel1 Left = 6 - Height = 21 - Top = 342 - Width = 155 + Height = 22 + Top = 335 + Width = 151 Anchors = [akLeft, akBottom] BorderSpacing.Around = 6 Caption = 'Case insensitive sort' diff --git a/components/rx/rxsortby.pas b/components/rx/rxsortby.pas index e6914aa59..d39f5084e 100644 --- a/components/rx/rxsortby.pas +++ b/components/rx/rxsortby.pas @@ -31,13 +31,13 @@ unit rxsortby; -{$mode objfpc}{$H+} +{$I rx.inc} interface uses Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs, - StdCtrls, Buttons, ButtonPanel, db; + StdCtrls, Buttons, ButtonPanel, rxdbgrid, db; type @@ -58,25 +58,23 @@ type UpBtn: TBitBtn; procedure AddBtnClick(Sender: TObject); procedure DownBtnClick(Sender: TObject); - procedure FormClose(Sender: TObject; var CloseAction: TCloseAction); procedure FormCreate(Sender: TObject); procedure ListBox1DblClick(Sender: TObject); procedure ListBox2DblClick(Sender: TObject); procedure RemoveBtnClick(Sender: TObject); procedure UpBtnClick(Sender: TObject); private - OrderListTemp: TStringList; - OrderAsc:boolean; + public { public declarations } - function Execute(adoTable : TDataSet; SortFieldNames:TStringList; var Asc:boolean):Boolean; + function Execute(ADBGrid:TRxDBGrid; SortFieldNames:TStringList; var Asc:boolean):Boolean; end; var rxSortByForm: TrxSortByForm; implementation -uses rxdconst; +uses rxdconst, DBGrids; {$R *.lfm} @@ -85,29 +83,22 @@ uses rxdconst; procedure TrxSortByForm.DownBtnClick(Sender: TObject); var TmpField:String; - Poz : Integer; + C1:TObject; + Poz: Integer; begin if ListBox1.ItemIndex < ListBox1.Items.Count-1 Then begin Poz:=ListBox1.ItemIndex; - TmpField:=ListBox1.Items[Poz+1]; - ListBox1.Items[Poz+1]:=ListBox1.Items[Poz]; - ListBox1.Items[Poz]:=TmpField; - ListBox1.ItemIndex:=Poz+1; - end; -end; -procedure TrxSortByForm.FormClose(Sender: TObject; var CloseAction: TCloseAction - ); -var - X:Integer; -begin - if ModalResult = mrOk then - begin - OrderAsc:=(ComboBox1.ItemIndex=0); - OrderListTemp.Clear; - for X:=0 To ListBox1.Items.Count-1 do - OrderListTemp.Add(ListBox1.Items[X]); + TmpField:=ListBox1.Items[Poz+1]; + C1:=ListBox1.Items.Objects[Poz+1]; + + ListBox1.Items[Poz+1]:=ListBox1.Items[Poz]; + ListBox1.Items.Objects[Poz+1]:=ListBox1.Items.Objects[Poz]; + + ListBox1.Items[Poz]:=TmpField; + ListBox1.Items.Objects[Poz]:=C1; + ListBox1.ItemIndex:=Poz+1; end; end; @@ -143,7 +134,7 @@ procedure TrxSortByForm.AddBtnClick(Sender: TObject); begin if ListBox2.ItemIndex <> -1 Then begin - ListBox1.Items.Add(ListBox2.Items.Strings[ListBox2.ItemIndex]); + ListBox1.Items.Objects[ListBox1.Items.Add(ListBox2.Items[ListBox2.ItemIndex])]:=ListBox2.Items.Objects[ListBox2.ItemIndex]; ListBox2.Items.Delete(ListBox2.ItemIndex); ListBox1.ItemIndex:=ListBox1.Items.Count-1; end; @@ -153,7 +144,7 @@ procedure TrxSortByForm.RemoveBtnClick(Sender: TObject); begin if ListBox1.ItemIndex <> -1 Then begin - ListBox2.Items.Add(ListBox1.Items.Strings[ListBox1.ItemIndex]); + ListBox2.Items.Objects[ListBox2.Items.Add(ListBox1.Items[ListBox1.ItemIndex])]:=ListBox1.Items.Objects[ListBox1.ItemIndex]; ListBox1.Items.Delete(ListBox1.ItemIndex); end; end; @@ -162,61 +153,66 @@ procedure TrxSortByForm.UpBtnClick(Sender: TObject); var TmpField:String; Poz : Integer; + C1:TObject; begin if ListBox1.ItemIndex > 0 Then begin Poz:=ListBox1.ItemIndex; TmpField:=ListBox1.Items[Poz-1]; + C1:=ListBox1.Items.Objects[Poz-1]; + ListBox1.Items[Poz-1]:=ListBox1.Items[Poz]; + ListBox1.Items.Objects[Poz-1]:=ListBox1.Items.Objects[Poz]; + ListBox1.Items[Poz]:=TmpField; + ListBox1.Items.Objects[Poz]:=C1; + ListBox1.ItemIndex:=Poz-1; end; end; -function TrxSortByForm.Execute(adoTable : TDataSet; SortFieldNames: TStringList; var Asc:boolean): Boolean; +function TrxSortByForm.Execute(ADBGrid: TRxDBGrid; + SortFieldNames: TStringList; var Asc: boolean): Boolean; var - X,P : Integer; + i, j : Integer; S : String; - SortFieldNamesTmp : TStringList; + C:TColumn; begin Result:=False; + if not (Assigned(ADBGrid.DataSource) and Assigned(ADBGrid.DataSource.DataSet) and ADBGrid.DataSource.DataSet.Active) then exit; + ListBox1.Clear; + ListBox2.Clear; + if not Asc then ComboBox1.ItemIndex:=1 else ComboBox1.ItemIndex:=0; - SortFieldNamesTmp:=TStringList.Create; - for X:=0 to adoTable.FieldDefs.Count-1 do -// If (NOT adoTable.FieldDefs[X].FieldClass.IsBlob) Then - SortFieldNamesTmp.Add(adoTable.FieldDefs.Items[X].Name); - if SortFieldNames.Count > 0 Then - begin - ListBox1.Clear; - for X:=0 To SortFieldNames.Count-1 Do - begin - S:=SortFieldNames.Strings[X]; - ListBox1.Items.Add(S); - P:=SortFieldNamesTmp.IndexOF(SortFieldNames.Strings[X]); - if P > -1 then - SortFieldNamesTmp.Delete(P); - end; - end; - if SortFieldNamesTmp.Count > 0 then - begin - ListBox2.Clear; - for X:=0 To SortFieldNamesTmp.Count-1 do - ListBox2.Items.Add(SortFieldNamesTmp.Strings[X]); - end; - SortFieldNamesTmp.Free; - OrderListTemp:=SortFieldNames; - OrderAsc:=Asc; + for i:=0 to ADBGrid.Columns.Count-1 do + begin + C:=ADBGrid.Columns[i]; + if SortFieldNames.IndexOf(C.Field.FieldName) > -1 then + ListBox1.Items.Objects[ListBox1.Items.Add(C.Title.Caption)]:=C + else + ListBox2.Items.Objects[ListBox2.Items.Add(C.Title.Caption)]:=C; + end; + if ShowModal = mrOK Then begin - Asc:=OrderAsc; + Asc:= ComboBox1.ItemIndex = 0; + + SortFieldNames.Clear; + for i:=0 to ListBox1.Items.Count-1 do + begin + C:=ListBox1.Items.Objects[i] as TColumn; + SortFieldNames.Add(C.FieldName); + end; + Result:=True; end; end; end. +