How to implement debounce in Delphi XE8 Pascal?

127 views Asked by At

Working on this app in Delphi XE8 that has 2 TEdit components, one to filter by part number, the next to filter by description. Currently, it only has an onChange procedure, that refreshes the list of parts, but it calls an SQL query every time onChange is called. I need it to only call this query after the form is filled, hence why I'm leaning towards debounce. Also the onChange procedures simply call a Refresh procedure, and the SQL calls are made in there, so no need to get very technical with that.

1

There are 1 answers

0
Solerman Kaplon On

Use a TTimer with a interval of at least 300 (ms)

  • in the OnTimer, if there is a description or part number filled, do the DB query. Keep both as class/query variables so that you can check if you didn't already did the query for the same values
  • in the OnChange of description and part number, set the timer enabled to false and back to true so that it zeros the time and starts counting towards the interval again