Tommi Prami 130 Posted March 23, 2021 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
Tommi Prami 130 Posted March 23, 2021 One way seems to use GotoBookmark. Share this post Link to post
Bill Meyer 337 Posted March 23, 2021 Dataset.Filter and Dataset.Filtered? Or are you looking for more than that? Share this post Link to post
Guest Posted March 23, 2021 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 Posted March 23, 2021 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
Tommi Prami 130 Posted March 24, 2021 (edited) 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 March 24, 2021 by Tommi Prami Share this post Link to post
Guest Posted March 24, 2021 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 Posted March 24, 2021 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
Tommi Prami 130 Posted March 26, 2021 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
Tommi Prami 130 Posted March 26, 2021 (edited) 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 March 26, 2021 by Tommi Prami Share this post Link to post
Cristian Peța 103 Posted March 26, 2021 (edited) DataSet.Filtered := False; DataSet.Filtered := True; Is working for me when using OnFilterRecord event. Edited March 26, 2021 by Cristian Peța Share this post Link to post
Tommi Prami 130 Posted March 26, 2021 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
Cristian Peța 103 Posted March 26, 2021 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
Tommi Prami 130 Posted March 26, 2021 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