Jump to content
Sign in to follow this  
Tommi Prami

How to kick TDataset to filter record(s)

Recommended Posts

Hello,

 

Is there a way to tell TDataset that now would be preferred time to do some filtering of records? Current record or all.

 

-Tee-

Share this post


Link to post
Guest

hi @Tommi Prami 

 

Your question is not really enlightening, but trying to understand its use, perhaps if you evaluated the amount of records returned by your Dataset, perhaps, this could be an indication of whether or not to use record filtering.

Do you understand my point of view?

 

some like this:

if xDataSet.Recount > n then
begin
  xDataSet.Filtered := false;
  xDataSet.Filter = 'xxxx';
  xDataSet.Filtered := true;
end;

 

hug

Share this post


Link to post
Guest

Do you use a DX Grid in "SmartRefresh" mode? You would have to call UpdateItems on the gridview.

 

Other controls should update, AFAIK, ctrl+click on the "Filtered" property.

In the "base" TDataSet class this calls SetFiltered(Value: Boolean), not much else happens (it's not supposed to be used plainly i think).

In the TClientDataSet class that procedure is overriden to CheckBrowseMode and navigate after the filter is activated.

TKbmMemTable has what looks like a complete system of it's own to manage this.

 

So IMHO you have to check the implementation of SetFiltered in you TDataSet decendant.

Share this post


Link to post

Problem was that I Have filtered dataset, but the Filtering criteria or filtered rows criteria is changed separate from data on dataset..

I have something like:


function KickDatasetFilterRecord(const ADataSet: TDataSet): TBookmark;
var
  LBookmark: TBookmark;
begin
  LBookmark := ADataSet.GetBookmark;
  try
    if not ADataSet.Eof then
      ADataSet.Next
    else
      ADataSet.Prior;

    Result := ADataSet.GetBookmark;
  finally
    if ADataSet.BookmarkValid(LBookmark) then
      ADataSet.GotoBookmark(LBookmark);
  end;
end;



procedure Foo(const AEmail: string);
begin
  FFilteredEmails.Add(AEmail) ;

  // Filter current wor now.
  Dataset.GotoBookmark(KickDatasetFilterRecord(Dataset));
end;

Edited by Tommi Prami

Share this post


Link to post
Guest
1 hour ago, Tommi Prami said:

Result := ADataSet.GetBookmark; 

... 

ADataSet.GotoBookmark(LBookmark);

hi @Tommi Prami 

Im try understand what is the "end propuse here" - what you're really doing ?

I think that your "problem" if really between this 2 rows!

  • first, you define the "result as the "Bookmark current" - then, the result was defined...
  • later, you re-positioning your dataset to old "Bookmark" - if "LBookmark is valid?" -- then, the dataset would have a other resulted...
  • is there here a insconsistence between they?

I would like to know what your real necessity on this task, if possible, of course.

 

hug

Share this post


Link to post
Guest
4 hours ago, Tommi Prami said:

Problem was that I Have filtered dataset, but the Filtering criteria or filtered rows criteria is changed separate from data on dataset..

You lost med there. I do not see a call to any filter function in the code.

Share this post


Link to post
On 3/24/2021 at 6:29 PM, Dany Marmur said:

You lost med there. I do not see a call to any filter function in the code.

Hmmm...

 

No wonder...  🙂

 

Dataset have emails, I load filtered emails on startup to the TSringList. Andf use OnFilerRecord (Etc event of dataset to filter those out).

I need also to filtr out rows from dataset on runtime, and I need to kick the TDataset  that Hey Dude, Filter current work right now. And code above more than less filled my need. Using GotoBookMark().

 

-Tee-

Share this post


Link to post
On 3/24/2021 at 3:26 PM, emailx45 said:

hi @Tommi Prami 

Im try understand what is the "end propuse here" - what you're really doing ?

I think that your "problem" if really between this 2 rows!

  • first, you define the "result as the "Bookmark current" - then, the result was defined...
  • later, you re-positioning your dataset to old "Bookmark" - if "LBookmark is valid?" -- then, the dataset would have a other resulted...
  • is there here a insconsistence between they?

I would like to know what your real necessity on this task, if possible, of course.

 

hug

I do not present the problem at there. That was my Quick and dirty solution to the problem

 

-.Tee.-

Edited by Tommi Prami

Share this post


Link to post
DataSet.Filtered := False;
DataSet.Filtered := True;

Is working for me when using OnFilterRecord event.

Edited by Cristian Peța

Share this post


Link to post
17 minutes ago, Cristian Peța said:

DataSet.Filtered := False;
DataSet.Filtered := True;

Is working for me when using OnFilterRecord event.

Sure that works, but I think that filters whole dataset, which I did not want.

 

-Tee-

Share this post


Link to post

Yes, whole dataset, but how match it takes? What do you want to optimize?

Do you keep in memory more than some thousands records?

Share this post


Link to post
6 minutes ago, Cristian Peța said:

Yes, whole dataset, but how match it takes? What do you want to optimize?

Do you keep in memory more than some thousands records?

That is discussion of another time,. That code Above was satisfactory for my needs. 

 

But maybe helpful for some other tough. Or different use case.

 

Thanks for your suggestion.

 

-Tee-

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×