Initially, Label1.Caption equates to zero. Here is the source code:

procedure TForm1.FormMouseWheelDown(Sender: TObject; Shift: TShiftState; MousePos: TPoint; var Handled: Boolean); begin Label1.Caption:=IntToStr(StrToInt(Label1.Caption)+1); end; procedure TForm1.FormMouseWheelUp(Sender: TObject; Shift: TShiftState; MousePos: TPoint; var Handled: Boolean); begin Label1.Caption:=IntToStr(StrToInt(Label1.Caption)-1); end; 

My task is to catch how many times the action was performed by scrolling "Up" and "Down" and start the corresponding function. Is the source running, but why does it run twice ??? And how to make it run once?

  • Everything works fine. Down +1, up -1. - KiTE
  • Sorry, I forgot to say ... That's right +1 and -1 works if there are no other components on the form. But if you add the Edit or Button component and go to the "Tab th" components, or simply click the mouse, it immediately starts counting +2 and -2. - p_redator
  • @p_redator, do not forget to accept the correct answer. - angry
  • I have a similar problem with the C ++ application: MouseWheelDown & MouseWheelUp are processed twice by one mousewheel step. Is there an analogue in Hand With: = True; ? - Toper Harley

2 answers 2

Add to each handler:

 Handled := True; 

to make it like this:

 procedure TForm1.FormMouseWheelDown(Sender: TObject; Shift: TShiftState; MousePos: TPoint; var Handled: Boolean); begin Handled := True; Label1.Caption:=IntToStr(StrToInt(Label1.Caption)+1); end; procedure TForm1.FormMouseWheelUp(Sender: TObject; Shift: TShiftState; MousePos: TPoint; var Handled: Boolean); begin Handled := True; Label1.Caption:=IntToStr(StrToInt(Label1.Caption)-1); end; 

Will count only once.

  • Thank you very much! Works like a clock! On the components of Edit or Button, this method works, and in DBGrid this source does not work through the procedures "FormMouseWheelDown" and "FormMouseWheelUp". Do not tell me what to do? or for this you need to create a new question? - p_redator
  • The standard scrolling behavior in DBGrid does not depend on the OnMouseWheelDown and OnMouseWheelUp event handlers on the form. How to solve the issue right away I will not tell you, because I have not used it in my projects for a long time. - KiTE
  • And can you tell me what component you are using instead of DBGrid? - p_redator
  • For simple tables cxDBGrid (package DevExpress). It maintains a link to the data source via the DataSource. If you need a flexible customization option, then VirtualStringTree (from [VirtualTreeView] [1]). [1]: code.google.com/p/virtual-treeview - KiTE
  • Are you sure that there is a "scrolling" in the cxDBGrid package and you can catch it ??? rxlib.ru/rx/rxDBAware/RxDBGrid/index.htm Events (Events) Key events are described here and nothing like that is described there. Tried to install EhLib I do everything on instructions and click Compile then Instal and it tells me "Cannot load package Ehlib60. It contains unit DBgridEh which is also contained dclusr60 " - p_redator

In general, I advise you to use the UpDown component on the Win32 panel for this purpose.

  • Perhaps I misunderstand something, but how can I use the UpDown component if I have a task to catch the scrolling and it is desirable that the procedure be performed once. - p_redator
  • You can install the UpDown component in the Associate property of the Edit you need, then you must catch the scrolling in the form with the events "FormMouseWheelDown" and "FormMouseWheelUp", and finally, if the scrolling is caught, then set the input focus to Edit1. (Edit1.SetFocus ()) - AseN
  • Thank you very much for the response, but the events "FormMouseWheelDown" and "FormMouseWheelUp" are caught without the UpDown component. - p_redator