Board index » delphi » Problems with TTrackBar

Problems with TTrackBar

When I click the mouse on the cursor of a TrackBar, at position=0, the
cursor moves, for exaample 2-4 positions.

The OnChange event is raised, and I check this with a
ShowMesssage(...position) at the OnChange event.
And this procedure seems to be invoked 3 times.
I take care to click just on center of the cursor, and not to move the
mouse. In addition, I have repeated this operation a lot of times:
always the same result.

Thank you.

 

Re:Problems with TTrackBar


Quote
In article <3ed7921...@newsgroups.borland.com>, Calabetta wrote:
> When I click the mouse on the cursor of a TrackBar, at position=0, the
> cursor moves, for exaample 2-4 positions.

> The OnChange event is raised, and I check this with a
> ShowMesssage(...position) at the OnChange event.
> And this procedure seems to be invoked 3 times.

Never use ShowMessage to track problems in event processing, showing a
dialog interrupts that and tends to foul up the debugging. Instead add
diagnostic strings to a memo or use OutputDebugString to send them to the
IDEs event log.

Anyway: the trackbar does indeed have a problem, it fires the OnChange
event when it gets an SB_ENDSCROLL message, in addition to the other
messages that indeed indicate a change of the trackbars position.

You can use the following trackbar derivative to fix the problem:

unit FixedTrackbar;

interface

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

type
  TFixedTrackbar = class(TTrackbar)
  private
    { Private declarations }
    procedure CNHScroll(var Message: TWMHScroll); message CN_HSCROLL;
    procedure CNVScroll(var Message: TWMVScroll); message CN_VSCROLL;
  protected
    { Protected declarations }
  public
    { Public declarations }
  published
    { Published declarations }
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('PBGoodies', [TFixedTrackbar]);
end;

{ TFixedTrackbar }

procedure TFixedTrackbar.CNHScroll(var Message: TWMHScroll);
begin
  If Message.ScrollCode <> SB_ENDSCROLL Then
    inherited;
end;

procedure TFixedTrackbar.CNVScroll(var Message: TWMVScroll);
begin
  If Message.ScrollCode <> SB_ENDSCROLL Then
    inherited;
end;

end.

--
Peter Below (TeamB)  
Use the newsgroup archives :
http://www.mers.com/searchsite.html
http://www.tamaracka.com/search.htm
http://groups.google.com
http://www.prolix.be

Re:Problems with TTrackBar


Quote
Peter Below (TeamB) wrote:
> In article <3ed7921...@newsgroups.borland.com>, Calabetta wrote:

>>When I click the mouse on the cursor of a TrackBar, at position=0, the
>>cursor moves, for exaample 2-4 positions.

>>The OnChange event is raised, and I check this with a
>>ShowMesssage(...position) at the OnChange event.
>>And this procedure seems to be invoked 3 times.

> Never use ShowMessage to track problems in event processing, showing a
> dialog interrupts that and tends to foul up the debugging. Instead add
> diagnostic strings to a memo or use OutputDebugString to send them to the
> IDEs event log.

I have installed the component TFixedTrackbar, and replaced TTrackBar in
the application.
The behaviour seems to be the same.
I do not have ShowMessage anymore, but the onEvent procedure does
something else, like assign TBar.hint, text.caption, ...
Does this too affect?

In a test program, both types of object work fine. But when clicking out
of the cursor, near but below the white bar, Position increases 2 units
each time.

Thank you.

Quote

> Anyway: the trackbar does indeed have a problem, it fires the OnChange
> event when it gets an SB_ENDSCROLL message, in addition to the other
> messages that indeed indicate a change of the trackbars position.

> You can use the following trackbar derivative to fix the problem:

> unit FixedTrackbar;

> interface

> uses
>   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
> Dialogs,
>   ComCtrls;

> type
>   TFixedTrackbar = class(TTrackbar)
>   private
>     { Private declarations }
>     procedure CNHScroll(var Message: TWMHScroll); message CN_HSCROLL;
>     procedure CNVScroll(var Message: TWMVScroll); message CN_VSCROLL;
>   protected
>     { Protected declarations }
>   public
>     { Public declarations }
>   published
>     { Published declarations }
>   end;

> procedure Register;

> implementation

> procedure Register;
> begin
>   RegisterComponents('PBGoodies', [TFixedTrackbar]);
> end;

> { TFixedTrackbar }

> procedure TFixedTrackbar.CNHScroll(var Message: TWMHScroll);
> begin
>   If Message.ScrollCode <> SB_ENDSCROLL Then
>     inherited;
> end;

> procedure TFixedTrackbar.CNVScroll(var Message: TWMVScroll);
> begin
>   If Message.ScrollCode <> SB_ENDSCROLL Then
>     inherited;
> end;

> end.

> --
> Peter Below (TeamB)  
> Use the newsgroup archives :
> http://www.mers.com/searchsite.html
> http://www.tamaracka.com/search.htm
> http://groups.google.com
> http://www.prolix.be

Re:Problems with TTrackBar


Quote
In article <3edcb14...@newsgroups.borland.com>, Calabetta wrote:
> The behaviour seems to be the same.

I may have misinterpreted your post. The component i posted fixes the problem
of the OnChange event firing too often.

The Pagesize property of the component controls how many unit the slider moves
when you click on the bar or use the page up/page down keys.

--
Peter Below (TeamB)  
Use the newsgroup archives :
http://www.mers.com/searchsite.html
http://www.tamaracka.com/search.htm
http://groups.google.com
http://www.prolix.be

Other Threads