From 40cb0c1012f0774c4f176538e84471cdbc2b2d60 Mon Sep 17 00:00:00 2001 From: alexs75 Date: Fri, 15 Feb 2013 06:46:24 +0000 Subject: [PATCH] RxDBGrid - Find Next now working git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@2685 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- components/rx/dbutils.pas | 40 ++++++++--- components/rx/rxdbgrid_findunit.lfm | 104 ++++++++++++++++------------ components/rx/rxdbgrid_findunit.pas | 18 ++++- components/rx/rxnew.lpk | 2 +- 4 files changed, 110 insertions(+), 54 deletions(-) diff --git a/components/rx/dbutils.pas b/components/rx/dbutils.pas index 90a61a818..78c5c19bb 100644 --- a/components/rx/dbutils.pas +++ b/components/rx/dbutils.pas @@ -48,6 +48,9 @@ const StringTypes = [ftString, {ftMemo,} ftFixedChar, ftWideString, ftFixedWideChar, ftWideMemo]; +type + TRxSearchDirection = (rsdAll, rsdForward, rsdBackward); + type { TLocateObject } @@ -107,7 +110,8 @@ procedure InternalRestoreFields(DataSet: TDataSet; IniFile: TObject; const Section: string; RestoreVisible: Boolean);} function DataSetLocateThrough(DataSet: TDataSet; const KeyFields: string; - const KeyValues: Variant; Options: TLocateOptions): Boolean; + const KeyValues: Variant; Options: TLocateOptions; SearchOrigin:TRxSearchDirection = rsdAll): Boolean; + procedure SaveFieldsReg(DataSet: TDataSet; IniFile: TRegIniFile); procedure RestoreFieldsReg(DataSet: TDataSet; IniFile: TRegIniFile; RestoreVisible: Boolean); @@ -379,7 +383,7 @@ end; { DataSet locate routines } function DataSetLocateThrough(DataSet: TDataSet; const KeyFields: string; - const KeyValues: Variant; Options: TLocateOptions): Boolean; + const KeyValues: Variant; Options: TLocateOptions; SearchOrigin:TRxSearchDirection = rsdAll): Boolean; var FieldCount: Integer; Fields: TList; @@ -430,20 +434,40 @@ begin try DataSet.GetFieldList(Fields, KeyFields); FieldCount := Fields.Count; - Result := CompareRecord; - if Result then Exit; + + if SearchOrigin = rsdAll then + begin + Result := CompareRecord; + if Result then Exit; + end; + DataSet.DisableControls; try Bookmark := DataSet.GetBookmark; try - with DataSet do begin - First; - while not EOF do begin + if SearchOrigin in [rsdAll, rsdForward] then + begin + if SearchOrigin = rsdAll then + DataSet.First; + while not DataSet.EOF do + begin Result := CompareRecord; if Result then Break; - Next; + DataSet.Next; + end; + end + else + if SearchOrigin = rsdBackward then + begin + //DataSet.Last; + while not DataSet.BOF do + begin + Result := CompareRecord; + if Result then Break; + DataSet.Prior; end; end; + finally {$IFDEF NoAutomatedBookmark} if not Result and DataSet.BookmarkValid(PChar(Bookmark)) then diff --git a/components/rx/rxdbgrid_findunit.lfm b/components/rx/rxdbgrid_findunit.lfm index 3eec12950..464dc3f5d 100644 --- a/components/rx/rxdbgrid_findunit.lfm +++ b/components/rx/rxdbgrid_findunit.lfm @@ -1,7 +1,7 @@ object rxDBGridFindForm: TrxDBGridFindForm - Left = 969 + Left = 688 Height = 225 - Top = 314 + Top = 327 Width = 493 ActiveControl = Edit1 Caption = 'Find' @@ -19,7 +19,7 @@ object rxDBGridFindForm: TrxDBGridFindForm Left = 6 Height = 15 Top = 6 - Width = 66 + Width = 69 BorderSpacing.Around = 6 Caption = 'Text to find' FocusControl = Edit1 @@ -34,7 +34,7 @@ object rxDBGridFindForm: TrxDBGridFindForm Left = 6 Height = 15 Top = 58 - Width = 68 + Width = 73 BorderSpacing.Around = 6 Caption = 'Find at filed' ParentColor = False @@ -44,9 +44,9 @@ object rxDBGridFindForm: TrxDBGridFindForm AnchorSideBottom.Control = Owner AnchorSideBottom.Side = asrBottom Left = 347 - Height = 35 - Top = 184 - Width = 79 + Height = 33 + Top = 186 + Width = 81 Anchors = [akRight, akBottom] AutoSize = True BorderSpacing.Around = 6 @@ -54,7 +54,7 @@ object rxDBGridFindForm: TrxDBGridFindForm Caption = 'Find more' Default = True OnClick = BtnFindClick - TabOrder = 4 + TabOrder = 2 end object Button2: TButton AnchorSideTop.Control = BtnFind @@ -63,10 +63,10 @@ object rxDBGridFindForm: TrxDBGridFindForm AnchorSideRight.Side = asrBottom AnchorSideBottom.Control = Owner AnchorSideBottom.Side = asrBottom - Left = 432 - Height = 35 - Top = 184 - Width = 55 + Left = 434 + Height = 33 + Top = 186 + Width = 53 Anchors = [akRight, akBottom] AutoSize = True BorderSpacing.Top = 8 @@ -75,7 +75,7 @@ object rxDBGridFindForm: TrxDBGridFindForm Cancel = True Caption = 'Close' OnClick = Button2Click - TabOrder = 5 + TabOrder = 3 end object Edit1: TEdit AnchorSideLeft.Control = ComboBox1 @@ -98,7 +98,7 @@ object rxDBGridFindForm: TrxDBGridFindForm AnchorSideRight.Control = Owner AnchorSideRight.Side = asrBottom Left = 12 - Height = 29 + Height = 27 Top = 79 Width = 475 Anchors = [akTop, akLeft, akRight] @@ -107,33 +107,25 @@ object rxDBGridFindForm: TrxDBGridFindForm Style = csDropDownList TabOrder = 1 end - object CheckBox1: TCheckBox - AnchorSideLeft.Control = Owner - AnchorSideTop.Control = ComboBox1 - AnchorSideTop.Side = asrBottom - Left = 6 - Height = 22 - Top = 114 - Width = 118 - BorderSpacing.Around = 6 - Caption = 'Case sensetive' - TabOrder = 2 - end object RadioGroup1: TRadioGroup - AnchorSideLeft.Control = CheckBox1 + AnchorSideLeft.Control = Panel1 AnchorSideLeft.Side = asrBottom AnchorSideTop.Control = ComboBox1 AnchorSideTop.Side = asrBottom AnchorSideRight.Control = Owner AnchorSideRight.Side = asrBottom - Left = 130 - Height = 51 - Top = 114 - Width = 357 - Anchors = [akTop, akLeft, akRight] + AnchorSideBottom.Control = Panel1 + AnchorSideBottom.Side = asrBottom + Left = 146 + Height = 62 + Top = 112 + Width = 341 + Anchors = [akTop, akLeft, akRight, akBottom] AutoFill = True AutoSize = True - BorderSpacing.Around = 6 + BorderSpacing.Left = 6 + BorderSpacing.Top = 6 + BorderSpacing.Right = 6 Caption = 'Direction' ChildSizing.LeftRightSpacing = 6 ChildSizing.TopBottomSpacing = 6 @@ -143,27 +135,51 @@ object rxDBGridFindForm: TrxDBGridFindForm ChildSizing.ShrinkVertical = crsScaleChilds ChildSizing.Layout = cclLeftToRightThenTopToBottom ChildSizing.ControlsPerLine = 3 - ClientHeight = 34 - ClientWidth = 353 + ClientHeight = 45 + ClientWidth = 337 Columns = 3 Items.Strings = ( 'All' 'Forward' 'Backward' ) - TabOrder = 6 - Visible = False + TabOrder = 4 end - object CheckBox2: TCheckBox + object Panel1: TPanel AnchorSideLeft.Control = Owner - AnchorSideTop.Control = CheckBox1 + AnchorSideTop.Control = ComboBox1 AnchorSideTop.Side = asrBottom Left = 6 - Height = 22 - Top = 142 - Width = 84 + Height = 62 + Top = 112 + Width = 134 + AutoSize = True BorderSpacing.Around = 6 - Caption = 'Partial key' - TabOrder = 3 + ClientHeight = 62 + ClientWidth = 134 + TabOrder = 5 + object CheckBox2: TCheckBox + AnchorSideLeft.Control = Panel1 + AnchorSideTop.Control = CheckBox1 + AnchorSideTop.Side = asrBottom + Left = 7 + Height = 21 + Top = 34 + Width = 88 + BorderSpacing.Around = 6 + Caption = 'Partial key' + TabOrder = 0 + end + object CheckBox1: TCheckBox + AnchorSideLeft.Control = Panel1 + AnchorSideTop.Control = Panel1 + Left = 7 + Height = 21 + Top = 7 + Width = 120 + BorderSpacing.Around = 6 + Caption = 'Case sensetive' + TabOrder = 1 + end end end diff --git a/components/rx/rxdbgrid_findunit.pas b/components/rx/rxdbgrid_findunit.pas index ca4e67197..fc9a1dd0a 100644 --- a/components/rx/rxdbgrid_findunit.pas +++ b/components/rx/rxdbgrid_findunit.pas @@ -52,6 +52,7 @@ type Edit1: TEdit; Label1: TLabel; Label2: TLabel; + Panel1: TPanel; RadioGroup1: TRadioGroup; procedure BtnFindClick(Sender: TObject); procedure Button2Click(Sender: TObject); @@ -103,6 +104,8 @@ begin RadioGroup1.Items.Add(sRxDbGridFindRangeBack); BtnFind.Caption:=sRxFindMore; Button2.Caption:=rsMbClose; + + RadioGroup1.ItemIndex:=0; end; procedure TrxDBGridFindForm.FormShow(Sender: TObject); @@ -114,6 +117,9 @@ procedure TrxDBGridFindForm.BtnFindClick(Sender: TObject); var FieldName:string; LOptions: TLocateOptions; + SearchOrigin:TRxSearchDirection; + P:TBookMark; + R:boolean; begin if Edit1.Text<>'' then begin @@ -125,8 +131,18 @@ begin if CheckBox2.Checked then LOptions:=LOptions+[loPartialKey]; - DataSetLocateThrough(FDataSet, FieldName, Edit1.Text, LOptions); + + SearchOrigin:=TRxSearchDirection(RadioGroup1.ItemIndex); + P:=FDataSet.Bookmark; + if SearchOrigin = rsdForward then + FDataSet.Next + else + if SearchOrigin = rsdBackward then + FDataSet.Prior; + R:=DataSetLocateThrough(FDataSet, FieldName, Edit1.Text, LOptions, SearchOrigin); finally + if not R then + FDataSet.Bookmark:=P; end; end; end; diff --git a/components/rx/rxnew.lpk b/components/rx/rxnew.lpk index 67073e3c5..c17903c5b 100644 --- a/components/rx/rxnew.lpk +++ b/components/rx/rxnew.lpk @@ -26,7 +26,7 @@ Copyright (c) 1998 Master-Bank translate to Lazarus by alexs in 2005 - 2012 "/> - +