Board index » delphi » Delayed scrolling / delayed OnChange?

Delayed scrolling / delayed OnChange?

Hi,

if a combobox has focus the user may use the up and down keys to
navigate through the items.

If the user keeps either key pressed and the change of the item
(ComboBox.OnChange) takes a long(ish) time an annoying delay will be
noticed.

As a "work around" I would like to react to the change of the
ItemIndex only after a short period of time, e.g. 100 ms.

I am aware of the solution that uses a TTimer that will be "reset" on
each change and finally trigger an update, but for resource reasons on
Win3.1 I strongly prefer a solution that does NOT use a TTimer.

Any ideas?
--
Stefan.Hoffmeis...@UNI-Passau.DE
http://kakadu.rz.uni-passau.de/~w4hoff01/
University of Passau, Bavaria, Germany

 

Re:Delayed scrolling / delayed OnChange?


Quote
Stefan Hoffmeister wrote:

> Hi,

> if a combobox has focus the user may use the up and down keys to
> navigate through the items.

> If the user keeps either key pressed and the change of the item
> (ComboBox.OnChange) takes a long(ish) time an annoying delay will be
> noticed.

> As a "work around" I would like to react to the change of the
> ItemIndex only after a short period of time, e.g. 100 ms.

> I am aware of the solution that uses a TTimer that will be "reset" on
> each change and finally trigger an update, but for resource reasons on
> Win3.1 I strongly prefer a solution that does NOT use a TTimer.

Here's an example. Written in D2, but technique should work OK in D1
too.
Just a simple form with a combo and a label. You probably should
consider using Yield in addition to the call to
Application.ProcessMessages, to avoid slowing down the PC when the forms
message queue is empty.

Regards,

Erik.

---
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs,
  StdCtrls;

const
  // Just some message constant
  PM_COMBOCHANGE = WM_USER + 8001;

  // 500 ms
  CWantedDelay = 500;

type
  TForm1 = class(TForm)
    ComboBox1: TComboBox;
    Label1: TLabel;
    procedure ComboBox1Change(Sender: TObject);
  private
    procedure PMComboChange(var message : TMessage); message
PM_COMBOCHANGE;
  public
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.ComboBox1Change(Sender: TObject);
begin
  PostMessage(Handle, PM_COMBOCHANGE, 0, 0);
end;

procedure TForm1.PMComboChange(var message : TMessage);
const
  InProc    : BOOLEAN = FALSE;
  StartTick : LONGINT = 0;
begin
  if InProc then begin
    // Update the starting time for the delay
    StartTick := GetTickCount;

  end else begin
    // We're in the loop
    InProc := TRUE;

    // Initial starting time
    StartTick := GetTickCount;

    // Wait until wanted time has elapsed.
    // If proc gets called again, starting time will change
    while GetTickCount - StartTick < CWantedDelay do
Application.ProcessMessages;

    // Increment a counter, just for illustration of when to do the
actual OnChange work
    Label1.Caption := IntToStr ( StrToIntDef ( Label1.Caption, 0 ) + 1
);

    // We're finished with the loop
    InProc := FALSE;
  end;
end;

end.

--
Need a custom component? Late on a project? Could use an util?
DOS Device driver? A VxD? NT drivers or services?
Applications of any kind?
Low rates, fast delivery!

When responding to news postings, please CC a copy to my email address.
Thanks.
Erik Sperling Johansen <e...@info-pro.no>

Other Threads