From 30626980e7466cf2fadcb9d172ca8d204ab8cec1 Mon Sep 17 00:00:00 2001 From: alexs75 Date: Tue, 8 Nov 2016 08:10:02 +0000 Subject: [PATCH] RxFPC: new property for RxDBGrid - SearchOptions - options for quick search in RxDBGrid git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@5324 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- components/rx/trunk/rxdbgrid.pas | 67 +++++++++++++++++++++++-------- components/rx/trunk/rxdbutils.pas | 16 ++++++-- 2 files changed, 62 insertions(+), 21 deletions(-) diff --git a/components/rx/trunk/rxdbgrid.pas b/components/rx/trunk/rxdbgrid.pas index e8dc70656..d7ae669b6 100644 --- a/components/rx/trunk/rxdbgrid.pas +++ b/components/rx/trunk/rxdbgrid.pas @@ -118,9 +118,8 @@ type ); - //TRxDSState = (rxdsInactive, rxdsActive); - TRxFilterOpCode = (fopEQ, fopNotEQ, fopStartFrom, fopEndTo, fopLike, fopNotLike); + { TRxDBGridKeyStroke } TRxDBGridKeyStroke = class(TCollectionItem) @@ -162,6 +161,22 @@ type property Items[Index: integer]: TRxDBGridKeyStroke read GetItem write SetItem; default; end; + { TRxDBGridSearchOptions } + + TRxDBGridSearchOptions = class(TPersistent) + private + FFromStart: boolean; + FOwner:TRxDBGrid; + FQuickSearchOptions: TLocateOptions; + protected + procedure AssignTo(Dest: TPersistent); override; + public + constructor Create(AOwner: TRxDBGrid); + published + property QuickSearchOptions:TLocateOptions read FQuickSearchOptions write FQuickSearchOptions; + property FromStart:boolean read FFromStart write FFromStart; + end; + { TRxDBGridCollumnConstraint } TRxDBGridCollumnConstraints = class(TPersistent) @@ -561,6 +576,7 @@ type FColumnDefValues: TRxDBGridColumnDefValues; //FrxDSState:TRxDSState; FFooterOptions: TRxDBGridFooterOptions; + FSearchOptions: TRxDBGridSearchOptions; FSortColumns: TRxDbGridColumnsSortList; FSortingNow:Boolean; FInProcessCalc: integer; @@ -635,6 +651,7 @@ type procedure SetKeyStrokes(const AValue: TRxDBGridKeyStrokes); procedure SetOptionsRx(const AValue: TOptionsRx); procedure SetPropertyStorage(const AValue: TCustomPropertyStorage); + procedure SetSearchOptions(AValue: TRxDBGridSearchOptions); procedure SetTitleButtons(const AValue: boolean); procedure TrackButton(X, Y: integer); function GetDrawFullLine: boolean; @@ -789,8 +806,6 @@ type property SortOrder:TSortMarker read GetSortOrder; property SortColumns:TRxDbGridColumnsSortList read FSortColumns; - //property MarkerUp : TBitmap read GetMarkerUp write SetMarkerUp; - //property MarkerDown : TBitmap read GetMarkerDown write SetMarkerDown; published property AfterQuickSearch: TRxQuickSearchNotifyEvent read FAfterQuickSearch write FAfterQuickSearch; property ColumnDefValues:TRxDBGridColumnDefValues read FColumnDefValues write SetColumnDefValues; @@ -802,6 +817,7 @@ type property Columns: TRxDbGridColumns read GetColumns write SetColumns stored IsColumnsStored; property KeyStrokes: TRxDBGridKeyStrokes read FKeyStrokes write SetKeyStrokes; property FooterOptions:TRxDBGridFooterOptions read FFooterOptions write SetFooterOptions; + property SearchOptions:TRxDBGridSearchOptions read FSearchOptions write SetSearchOptions; //storage property PropertyStorage: TCustomPropertyStorage read GetPropertyStorage write SetPropertyStorage; @@ -1055,6 +1071,27 @@ type procedure EditingDone; override; end; +{ TRxDBGridSearchOptions } + +procedure TRxDBGridSearchOptions.AssignTo(Dest: TPersistent); +begin + if Dest is TRxDBGridSearchOptions then + begin + TRxDBGridSearchOptions(Dest).FQuickSearchOptions:=FQuickSearchOptions; + TRxDBGridSearchOptions(Dest).FFromStart:=FFromStart; + end + else + inherited AssignTo(Dest); +end; + +constructor TRxDBGridSearchOptions.Create(AOwner: TRxDBGrid); +begin + inherited Create; + FOwner:=AOwner; + FQuickSearchOptions:=[loPartialKey, loCaseInsensitive]; + FFromStart:=false; +end; + { TRxDBGridColumnDefValues } procedure TRxDBGridColumnDefValues.AssignTo(Dest: TPersistent); @@ -2617,6 +2654,11 @@ begin FPropertyStorageLink.Storage := AValue; end; +procedure TRxDBGrid.SetSearchOptions(AValue: TRxDBGridSearchOptions); +begin + FSearchOptions.Assign(AValue); +end; + function TRxDBGrid.DatalinkActive: boolean; begin Result := Assigned(DataSource) and Assigned(DataSource.DataSet) and @@ -4372,7 +4414,7 @@ begin begin //1.Вызываем процедурку поиска... if DataSetLocateThrough(Self.DataSource.DataSet, - Self.SelectedField.FieldName, AValue, [loPartialKey, loCaseInsensitive]) then + Self.SelectedField.FieldName, AValue, FSearchOptions.FQuickSearchOptions, rsdAll, FSearchOptions.FFromStart) then Self.FQuickUTF8Search := AValue; ClearSearchValue := False; end; @@ -5630,6 +5672,7 @@ begin {$ENDIF} FToolsList:=TFPList.Create; FColumnDefValues:=TRxDBGridColumnDefValues.Create(Self); + FSearchOptions:=TRxDBGridSearchOptions.Create(Self); FSortColumns:=TRxDbGridColumnsSortList.Create; @@ -5681,29 +5724,19 @@ end; destructor TRxDBGrid.Destroy; begin CleanDSEvent; - FreeAndNil(FFooterOptions); - FreeAndNil(FRxDbGridLookupComboEditor); FreeAndNil(FRxDbGridDateEditor); - //FreeAndNil(FMarkerDown); - //FreeAndNil(FMarkerUp); FreeAndNil(FPropertyStorageLink); FreeAndNil(FFilterListEditor); - FreeAndNil(F_PopupMenu); FreeAndNil(F_MenuBMP); -{ FreeAndNil(FEllipsisRxBMP); - FreeAndNil(FGlyphRxBMP); - FreeAndNil(FUpDownRxBMP); - FreeAndNil(FPlusRxBMP); - FreeAndNil(FMinusRxBMP);} - FreeAndNil(F_LastFilter); - FreeAndNil(FKeyStrokes); FreeAndNil(FToolsList); FreeAndNil(FColumnDefValues); + FreeAndNil(FSearchOptions); + inherited Destroy; FreeAndNil(FSortColumns); end; diff --git a/components/rx/trunk/rxdbutils.pas b/components/rx/trunk/rxdbutils.pas index 2873e1c92..15c8a2d19 100644 --- a/components/rx/trunk/rxdbutils.pas +++ b/components/rx/trunk/rxdbutils.pas @@ -50,7 +50,6 @@ const type TRxSearchDirection = (rsdAll, rsdForward, rsdBackward); - type { TLocateObject } @@ -110,7 +109,7 @@ procedure InternalRestoreFields(DataSet: TDataSet; IniFile: TObject; const Section: string; RestoreVisible: Boolean);} function DataSetLocateThrough(DataSet: TDataSet; const KeyFields: string; - const KeyValues: Variant; Options: TLocateOptions; SearchOrigin:TRxSearchDirection = rsdAll): Boolean; + const KeyValues: Variant; Options: TLocateOptions; SearchOrigin:TRxSearchDirection = rsdAll; ASearchFromStart:boolean = false): Boolean; procedure SaveFieldsReg(DataSet: TDataSet; IniFile: TRegIniFile); procedure RestoreFieldsReg(DataSet: TDataSet; IniFile: TRegIniFile; @@ -384,7 +383,8 @@ end; { DataSet locate routines } function DataSetLocateThrough(DataSet: TDataSet; const KeyFields: string; - const KeyValues: Variant; Options: TLocateOptions; SearchOrigin:TRxSearchDirection = rsdAll): Boolean; + const KeyValues: Variant; Options: TLocateOptions; SearchOrigin:TRxSearchDirection = rsdAll; + ASearchFromStart:boolean = false): Boolean; var FieldCount: Integer; Fields: TList; @@ -415,7 +415,15 @@ var Result := UTF8CompareStr(S, S1) = 0;} if (loPartialKey in Options) then - Result := UTF8Pos(S1, S) > 0 + begin + if ASearchFromStart then + begin + UTF8Delete(S, UTF8Length(S1) + 1, MaxInt); + Result := UTF8CompareStr(S, S1) = 0; + end + else + Result := UTF8Pos(S1, S) > 0 + end else begin Result := UTF8CompareStr(S, S1) = 0;