RxFPC: add filter expression to TRxMemoryData

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@5081 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
alexs75
2016-08-12 07:37:17 +00:00
parent e534eade83
commit 2ddf545806
3 changed files with 98 additions and 15 deletions

View File

@ -171,6 +171,47 @@ begin
end; end;
procedure TRxDBGridExportPDF.DoExportTitle; procedure TRxDBGridExportPDF.DoExportTitle;
var
P: TPDFPage;
Pt: TPDFCoord;
i, X, CP, PX: Integer;
C: TRxColumn;
S: String;
PU: TPDFUnitOfMeasure;
begin
X:=FPageWidth + FPageMargin.Right;
CP:=-1;
PX:=0;
for i:=0 to FRxDBGrid.Columns.Count - 1 do
begin
C:=FRxDBGrid.Columns[i];
if X + C.Width > FPageWidth - FPageMargin.Right then
begin
Inc(CP);
P:=TPDFPage(FWorkPages[CP]);
X:=FPageMargin.Left;
PX:=0;
end;
Pt.X := X;
Pt.Y := FPosY;
P.SetColor(C.Color);
P.DrawRect(Pt.X, Pt.Y, C.Width, FRxDBGrid.DefaultRowHeight, 1, false, true);
P.SetFont(FHeaderFont, 10);
P.WriteText(Pt.X+2, Pt.Y-10, C.Title.Caption);
X:=X + C.Width;
end;
Inc(FPosY, FRxDBGrid.DefaultRowHeight);
end;
procedure TRxDBGridExportPDF.DoExportBody;
procedure DoWriteRow;
var var
P: TPDFPage; P: TPDFPage;
Pt: TPDFCoord; Pt: TPDFCoord;
@ -193,8 +234,11 @@ begin
P.DrawRect(Pt.X, Pt.Y, C.Width, FRxDBGrid.DefaultRowHeight, 1, false, true); P.DrawRect(Pt.X, Pt.Y, C.Width, FRxDBGrid.DefaultRowHeight, 1, false, true);
P.SetFont(FHeaderFont, 10); if Assigned(C.Field) then
P.WriteText(Pt.X+2, Pt.Y-10, C.Title.Caption); begin
P.SetFont(FBodyFont, 10);
P.WriteText(Pt.X+2, Pt.Y-10, C.Field.DisplayText);
end;
if X + C.Width > FPageWidth - FPageMargin.Right then if X + C.Width > FPageWidth - FPageMargin.Right then
begin begin
@ -205,14 +249,6 @@ begin
else else
Inc(X, C.Width); Inc(X, C.Width);
end; end;
Inc(FPosY, FRxDBGrid.DefaultRowHeight);
end;
procedure TRxDBGridExportPDF.DoExportBody;
procedure DoWriteRow;
begin
//
end; end;
begin begin
@ -290,13 +326,13 @@ begin
begin begin
if FPdfOptions.PaperOrientation = ppoPortrait then if FPdfOptions.PaperOrientation = ppoPortrait then
begin begin
FPageWidth := PDFPaperSizes[FPdfOptions.FPaperType, 0]; FPageWidth := PDFPaperSizes[FPdfOptions.FPaperType, 1];
FPageHeight := PDFPaperSizes[FPdfOptions.FPaperType, 1]; FPageHeight := PDFPaperSizes[FPdfOptions.FPaperType, 0];
end end
else else
begin begin
FPageWidth := PDFPaperSizes[FPdfOptions.FPaperType, 1]; FPageWidth := PDFPaperSizes[FPdfOptions.FPaperType, 0];
FPageHeight := PDFPaperSizes[FPdfOptions.FPaperType, 0]; FPageHeight := PDFPaperSizes[FPdfOptions.FPaperType, 1];
end; end;
W:=FPageMargin.Left; W:=FPageMargin.Left;

View File

@ -37,7 +37,7 @@ unit rxmemds;
interface interface
uses SysUtils, Classes, DB, ex_rx_datapacket; uses SysUtils, Classes, DB, ex_rx_datapacket, bufdataset_parser;
{ TRxMemoryData } { TRxMemoryData }
@ -72,6 +72,7 @@ type
FFilterBuffer : pchar; FFilterBuffer : pchar;
FNullmaskSize : byte; FNullmaskSize : byte;
FBRecordCount : integer; FBRecordCount : integer;
FParser : TBufDatasetParser;
function IntAllocRecordBuffer: PChar; function IntAllocRecordBuffer: PChar;
procedure IntLoadFielddefsFromFile; procedure IntLoadFielddefsFromFile;
procedure IntLoadRecordsFromFile; procedure IntLoadRecordsFromFile;
@ -94,6 +95,7 @@ type
procedure SetCapacity(Value: Integer); procedure SetCapacity(Value: Integer);
procedure ClearRecords; procedure ClearRecords;
procedure InitBufferPointers(GetProps: Boolean); procedure InitBufferPointers(GetProps: Boolean);
procedure ParseFilter(const AFilter: string);
protected protected
procedure AssignMemoryRecord(Rec: TMemoryRecord; Buffer: PChar); procedure AssignMemoryRecord(Rec: TMemoryRecord; Buffer: PChar);
function GetActiveRecBuf(var RecBuf: PChar): Boolean; virtual; function GetActiveRecBuf(var RecBuf: PChar): Boolean; virtual;
@ -146,6 +148,7 @@ type
procedure SetRecNo(Value: Integer); override; procedure SetRecNo(Value: Integer); override;
property Records[Index: Integer]: TMemoryRecord read GetMemoryRecord; property Records[Index: Integer]: TMemoryRecord read GetMemoryRecord;
function GetAnyRecField(SrcRecNo:integer; AField:TField):variant; function GetAnyRecField(SrcRecNo:integer; AField:TField):variant;
procedure SetFilterText(const Value: String); override;
public public
constructor Create(AOwner: TComponent); override; constructor Create(AOwner: TComponent); override;
destructor Destroy; override; destructor Destroy; override;
@ -483,6 +486,7 @@ end;
constructor TRxMemoryData.Create(AOwner: TComponent); constructor TRxMemoryData.Create(AOwner: TComponent);
begin begin
inherited Create(AOwner); inherited Create(AOwner);
FParser := nil;
FRecordPos := -1; FRecordPos := -1;
FLastID := Low(Integer); FLastID := Low(Integer);
FAutoInc := 1; FAutoInc := 1;
@ -496,6 +500,7 @@ begin
ClearRecords; ClearRecords;
FRecords.Free; FRecords.Free;
ReallocMem(FOffsets, 0); ReallocMem(FOffsets, 0);
if Assigned(FParser) then FreeAndNil(FParser);
end; end;
{ Records Management } { Records Management }
@ -638,6 +643,27 @@ begin
FRecBufSize := FBlobOfs + BlobFieldCount * SizeOf(TMemBlobData);//Pointer); FRecBufSize := FBlobOfs + BlobFieldCount * SizeOf(TMemBlobData);//Pointer);
end; end;
procedure TRxMemoryData.ParseFilter(const AFilter: string);
begin
// parser created?
if Length(AFilter) > 0 then
begin
if (FParser = nil) and IsCursorOpen then
begin
FParser := TBufDatasetParser.Create(Self);
end;
// is there a parser now?
if FParser <> nil then
begin
// set options
FParser.PartialMatch := not (foNoPartialCompare in FilterOptions);
FParser.CaseInsensitive := foCaseInsensitive in FilterOptions;
// parse expression
FParser.ParseExpression(AFilter);
end;
end;
end;
procedure TRxMemoryData.ClearRecords; procedure TRxMemoryData.ClearRecords;
begin begin
while FRecords.Count > 0 do TObject(FRecords.Last).Free; while FRecords.Count > 0 do TObject(FRecords.Last).Free;
@ -987,6 +1013,7 @@ end;
function TRxMemoryData.RecordFilter: Boolean; function TRxMemoryData.RecordFilter: Boolean;
var var
SaveState: TDataSetState; SaveState: TDataSetState;
RecBuf: PChar;
begin begin
Result := True; Result := True;
if Assigned(OnFilterRecord) then if Assigned(OnFilterRecord) then
@ -1000,6 +1027,13 @@ begin
except except
CustomApplication.HandleException(Self); CustomApplication.HandleException(Self);
end; end;
if Result and (Length(Filter) > 0) then
begin
if GetActiveRecBuf(RecBuf) then
Result := Boolean((FParser.ExtractFromBuffer(RecBuf))^);
end;
RestoreState(SaveState); RestoreState(SaveState);
end end
else else
@ -1342,6 +1376,18 @@ begin
end; end;
end; end;
procedure TRxMemoryData.SetFilterText(const Value: String);
begin
if Value = Filter then
exit;
// parse
ParseFilter(Value);
// call dataset method
inherited;
// refilter dataset if filtered
if IsCursorOpen and Filtered then Resync([]);
end;
function TRxMemoryData.IsSequenced: Boolean; function TRxMemoryData.IsSequenced: Boolean;
begin begin
Result := not Filtered; Result := not Filtered;

View File

@ -10,6 +10,7 @@
<Version Value="11"/> <Version Value="11"/>
<PathDelim Value="\"/> <PathDelim Value="\"/>
<SearchPaths> <SearchPaths>
<OtherUnitFiles Value="rxdb"/>
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/> <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths> </SearchPaths>
<Parsing> <Parsing>