views:

571

answers:

3

In Delphi, I've added a Scrollbar component (oriented vertical) to the right side of my form.

I've added a Scrollbar OnChange event so I can change the view of the form and the position of the scrollbar thumb when the user clicks on the UpArrow or DownArrow button with his mouse, and this works fine.

But the OnChange event only seems to get triggered when the mouse button is initially pressed on the arrow.

I notice all scrollbar controls repeat the command and continue scrolling while the mouse remains pressed on the arrow, and I'd like to implement this behavior.

So how can I easily detect if the user has not moved the mouse and continues to press the mouse button while the mouse remains over the arrow?


Conclusion. Somehow something in the scrollbar in my project got corrupted. After I deleted the ScrollBar, and added it again, the problem vanished.

This is one of those tricky ones that took me a lot of time to solve. Thanks for your help. I'm closing this question.

+4  A: 

Use the OnScroll event.

The following code adds 'xxx' to a memo as long as the mouse is held down on the scrollbar arrow button. Tested with Delphi 6.

procedure TForm1.ScrollBar1Scroll(Sender: TObject; ScrollCode: TScrollCode;
  var ScrollPos: Integer);
begin
    Memo1.Lines.Add( 'xxx' );
end;
anon
No. OnScroll does the same thing as OnChange to detect the initial click. But neither continually signals that the event should continue. They only process the initial button press once. I need to see if the mouse remains pressed so that I can continue the scrolling
lkessler
It works on my Delphi 6 installation - I just tested it.
anon
Thanks for checking that, Neil. Your test works as well in Delphi 2009. I think it has led me to the cause of the problem. The component (TElScrollBar) I use does not work like TScrollBar, so it is a problem with that component. I'll contact LMD about this.
lkessler
+2  A: 

The usual way to handle auto-repeating is to enable a TTimer and check in the OnTimer() event handler whether the action needs to be performed again, and to deactivate the timer if not. If you need sample code, I seem to remember that the SynEdit control used a similar technique for autoscrolling in drag and drop operations.

mghie
A: 

If a component does not encapsulate the behaviour you are looking for and you can't easily simulate the behaviour with the methods available you should really subclass the closest component that does most of what you need and add the behaviours that are missing.

I know that some extra work is involved but it really is the better way to go. Now with Delphi, I seem to recall that subclassed components needed a bit of extra work as well to be able to be used from the IDE for form design, maybe this has changed since version 7.

Arnold Spence
No extra work needed and never has been (I've been using Delphi since version 1.0)
anon