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
This commit is contained in:
alexs75
2016-11-08 08:10:02 +00:00
parent 4d79b47a51
commit 30626980e7
2 changed files with 62 additions and 21 deletions

View File

@ -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;

View File

@ -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;