|Home » Technical Support » Elevate Web Builder Technical Support » Support Forums » Elevate Web Builder General » View Thread|
|Messages 1 to 5 of 5 total|
|Grid - delayed OnRowChanged|
|Sat, Oct 21 2017 12:02 PM||Permanent Link|
I have a parent grid with an OnRowChanged property which performs a server request for child records when the row changes.
When I hold down the up/down keys or scroll fast in the grid, I do not want the OnRowChanged event to fire until I release the key or pause for X milliseconds to avoid unnecessary server request calls.
Would it be possible to have a DelayedRowChangeInterval property that you could set to delay the event firing?
Or is there another way to handle this?
|Sat, Oct 21 2017 2:59 PM||Permanent Link|
Have you thought about maybe using a TTimer to handle this?
|Mon, Oct 23 2017 3:54 AM||Permanent Link|
Mark Brooks wrote:
> Have you thought about maybe using a TTimer to handle this?
To expand on this, it is indeed exactly what I do. I brought up the idea of "delay" being built in on another aspect of events, and in typing came to the conclusion that it is better for the component to immediately inform, and then we as developers can choose what to do with that event, either acting immediately, or adding a delay.
The delay is simple - have a timer running at a fairly fast interval. Then in the event, set a boolean flag and the time that the action (lookup) should happen. In the timer, check if the flag is set, and if so, check if the time has passed. And if so, do the lookup.
procedure TfrmBlah.cboCategoryChange(Sender: TObject);
if not m_bLoaded then
m_bLookupNeeded := true;
m_tmDoLookupAt := IncMilliSecond(Now, cboCategory.KeyPressInterval);
TimerComboComplete.Enabled := true;
procedure TfrmBlah.TimerComboCompleteTimer(Sender: TObject);
if Now > m_tmDoLookupAt then
TimerComboComplete.Enabled := false;
IncMilliSecond came from code posted here by other helpful people IIRC.
I am assuming that enabling the timer multiple times is not resetting the clock - perhaps I should check that, but it works anyway!
|Mon, Oct 23 2017 12:14 PM||Permanent Link|
Tim Young [Elevate Software]
Elevate Software, Inc.
<< Would it be possible to have a DelayedRowChangeInterval property that you could set to delay the event firing? >>
I can't really delay the firing of the event, but...
<< Or is there another way to handle this? >>
Yes, there is. What you're trying to do is called de-bouncing and, as others have pointed out, the solution is to use a TTimer to achieve the result that you want. The general idea is that you disable and then re-enable the timer (the timer is initially disabled) whenever the event fires, and have the timer's OnTimer event trigger the code that you want to execute in a delayed fashion.
However, you *do* need to be careful with this type of setup because you could get into a situation where the dataset, or some property of the dataset, has been freed or changed between the time that the OnRowChanged event has fired and the OnTimer (your code) is executed.
|Mon, Oct 23 2017 3:55 PM||Permanent Link|
Thanks, guys. Lots of good info here to get me started.