Discussion:
How to perform an internal TTable.onFilterRecord?
(too old to reply)
Felix Porsch
2004-01-22 12:08:15 UTC
Permalink
I want to have a specialized class derived from TTable (lets call it
TAttrTable) which
performs some filtering controlled by the property TAttrTable.Attribute.

For this I could use the onFilterRecord-event but than this event is no
more free at design time.
How can I hook an internal filter operation?

felix
Nick Hodges (TeamB)
2004-01-24 03:10:24 UTC
Permalink
Post by Felix Porsch
I want to have a specialized class derived from TTable (lets call it
TAttrTable) which
performs some filtering controlled by the property
TAttrTable.Attribute.
For this I could use the onFilterRecord-event but than this event is
no more free at design time.
How can I hook an internal filter operation?
Yeah, sadly, this is going to be tough to do. OnFilterRecord doesn't
have a simple way to hook into it -- it's called in the RecordFilter
method which is private, and thus not virtual.

You might give SetOnFilterRecord a look -- you might be able to hook in
that way.
--
Nick Hodges (TeamB)
Lemanix Corporation - (http://www.lemanix.com)
Improve the quality of Delphi! Get your bugs into QC:
http://qc.borland.com
Felix Porsch
2004-01-25 23:50:33 UTC
Permalink
Post by Nick Hodges (TeamB)
Yeah, sadly, this is going to be tough to do. OnFilterRecord doesn't
have a simple way to hook into it -- it's called in the RecordFilter
method which is private, and thus not virtual.
You might give SetOnFilterRecord a look -- you might be able to hook in
that way.
Thanks for the hint.
There were some pitfalls on the way but now I have it.

May be it's of interest:

type
TAttribute = longInt; // as TIntegerField

TAttrTable = class(TTable)
private
FAttrFiltered: Boolean;
FAttrFilter: TAttribute;
FExtOnFilterRecord : TFilterRecordEvent;
procedure SetAttrFiltered(const Value: Boolean);
procedure FilterRecordAttributes(DataSet: TDataSet; var Accept:
Boolean);
procedure SetAttrFilter(const Value: TAttribute);
protected
procedure DoBeforeOpen; override;
function GetOnFilterRecord : TFilterRecordEvent;
procedure SetOnFilterRecord(const Value: TFilterRecordEvent);
override;
public
constructor Create(AOwner: TComponent); override;
published
property AttrFilter : TAttribute read FAttrFilter write
SetAttrFilter;
property AttrFiltered : Boolean read FAttrFiltered write
SetAttrFiltered;
property OnFilterRecord: TFilterRecordEvent read
GetOnFilterRecord write SetOnFilterRecord;
end;


implementation


{ TAttrTable }

constructor TAttrTable.Create(AOwner: TComponent);
begin
inherited;
FAttrFiltered:= false;
FAttrFilter:= 0;
FExtOnFilterRecord:= NIL;
inherited setOnFilterRecord(FilterRecordAttributes);
end;

procedure TAttrTable.FilterRecordAttributes(DataSet: TDataSet; var
Accept: Boolean);
begin
if Accept then begin
if AttrFiltered then Accept:= ((AttrField.AsInteger and
AttrFilter) = AttrFilter);
if Accept and assigned(FExtOnFilterRecord) then
FExtOnFilterRecord(DataSet, Accept);
end; // else already false
end;

function TAttrTable.GetOnFilterRecord: TFilterRecordEvent;
begin
result:= FExtOnFilterRecord;
end;

procedure TAttrTable.SetAttrFilter(const Value: TAttribute);
begin
if FAttrFilter <> Value then begin
FAttrFilter := Value;
if Filtered and AttrFiltered and active then refresh;
end;
end;

procedure TAttrTable.SetAttrFiltered(const Value: Boolean);
begin
if FAttrFiltered <> Value then begin
FAttrFiltered := Value;
if Filtered and active then refresh;
end;
end;

procedure TAttrTable.setOnFilterRecord(const Value:
TFilterRecordEvent);
begin
FExtOnFilterRecord:= value;
inherited setOnFilterRecord(FilterRecordAttributes);
end;

end.

Loading...