I am trying to develop a new TEdit-Component.
TDBFilterEdit = class(TEdit)
The component is meant to Filter an associated DataSet based on the string that is entered in its Edit-Field.
this is what my component looks like:
type
TDBFilterEdit = class(TEdit)
private
{ Private-Deklarationen }
fFilter:String;
fDataSource:TDataSource;
fDataSet:TDataSet;
fText:string;
protected
{ Protected-Deklarationen }
procedure SetFilter(value:String);
procedure SetDS(value:TDataSource);
procedure FilterRecords(DataSet:TDataSet; var Accept:Boolean);
procedure Change(Sender:TObject);
procedure SetText(value:String);
public
{ Public-Deklarationen }
constructor Create(AOwner:TComponent);
published
{ Published-Deklarationen }
property Text:String read fText write SetText;
property Filter:String read fFilter write SetFilter;
property DataSource:TDataSource read fDataSource write SetDS;
end;
Now, I am pretty Novice when it comes to component-development. My first Idea was to Override the OnFilterRecord-method of the Dataset as soon as the DataSource gets assigned to my component and trigger it whenever the text of my Edit-component changes.
procedure TDBFilterEdit.SetDS(value:TDataSource);
var
myaccept:Boolean;
begin
fDataSource:=value;
fDataSet:=fDataSource.DataSet;
if fDataSet=nil then Exit;
fDataSet.OnFilterRecord:=FilterRecords;
if Filter<>'' then fDataSet.OnFilterRecord(fDataSet,myaccept);
end;
My Problem is, I don't know how to make the component aware that its Text-property got updated. I tried overriding the OnChange-Method with following code
procedure TDBFilterEdit.Change(Sender:TObject);
begin
Filter:=Text;
inherited Change();
end;
however, to no avail so far.