Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2014-04

Scroll Wheel

6 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Timothy Groves

I have several TEdit objects in my form, and because they handle only integer data, I'd like to use my scroll wheel to edit their values. However, there is no OnScrollWheel event that I can see.

Since scroll wheels are passed as mouse clicks, I thought to examine the OnMouseDown/OnMouseUp events, but nothing is passed to indicate /which/ button is being pressed.

So either Google has failed me, or I have failed Google, but either way, I can't find the answer on the net after an hour of searching. Can anyone point me in the right direction?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20140411/a7713368/attachment-0001.html>

Reply by email

Mattias Gaertner
to Timothy Groves
Show quoted text 11 lines
I have several TEdit objects in my form, and because they handle only integer data, I'd like to use my scroll wheel to edit their values. However, there is no OnScrollWheel event that I can see. Since scroll wheels are passed as mouse clicks, I thought to examine the OnMouseDown/OnMouseUp events, but nothing is passed to indicate /which/ button is being pressed. So either Google has failed me, or I have failed Google, but either way, I can't find the answer on the net after an hour of searching. Can anyone point me in the right direction?

Have you tried to override

    procedure WMMouseWheel(var Message: TLMMouseEvent); message LM_MOUSEWHEEL;

?

Mattias

Reply by email

Timothy Groves
to Mattias Gaertner

No; I am unsure as to how to do that. Would I need to create a descendant class, or does Lazarus support overriding without doing so?

"Chess is an exciting game, when played with shotguns." --MegaHAL

"Mattias Gaertner" wrote 28 lines
On Fri, 11 Apr 2014 13:45:41 -0400 Timothy Groves wrote: > I have several TEdit objects in my form, and because they handle only > integer data, I'd like to use my scroll wheel to edit their values. > However, there is no OnScrollWheel event that I can see. > > Since scroll wheels are passed as mouse clicks, I thought to examine the > OnMouseDown/OnMouseUp events, but nothing is passed to indicate /which/ > button is being pressed. > > So either Google has failed me, or I have failed Google, but either way, > I can't find the answer on the net after an hour of searching. Can > anyone point me in the right direction? Have you tried to override procedure WMMouseWheel(var Message: TLMMouseEvent); message LM_MOUSEWHEEL; ? Mattias -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20140411/75d5f3d2/attachment.html>

Reply by email

Chris Kelling

I did a search on mouse wheel event delphi - I came up with a lot of articles, most mentioning OnMessage event. Then there was this article, which I've not read all the way, but you may find useful. I'm not sure if this was ported to Lazarus, but I've found referencing Delphi does garner solutions most times.

http://mc-computing.com/languages/Delphi/ScrollWheel.html

-Chris

-------- Everything at or below the line is a signature, not to be confused with the body of the email above. Sorry about the last signature text that seemed to have some people questioning my sanity.

We are what we repeatedly do. Excellence, then, is not an act, but a habit.

-Aristotle

Show quoted text 12 lines
On Apr 11, 2014, at 13:45, Timothy Groves wrote: I have several TEdit objects in my form, and because they handle only integer data, I'd like to use my scroll wheel to edit their values. However, there is no OnScrollWheel event that I can see. Since scroll wheels are passed as mouse clicks, I thought to examine the OnMouseDown/OnMouseUp events, but nothing is passed to indicate which button is being pressed. So either Google has failed me, or I have failed Google, but either way, I can't find the answer on the net after an hour of searching. Can anyone point me in the right direction? -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20140411/faa8e5fb/attachment.html>

Reply by email

Howard Page-Clark
to Timothy Groves: No; I am unsure as to how to do that. Would I need to create a descendant class, or does…
Timothy Groves wrote
No; I am unsure as to how to do that. Would I need to create a descendant class, or does Lazarus support overriding without doing so?

The following should give you an idea how to develop the hint Mattias gave:

===code===
unit testIntWheelEdit;
{$mode objfpc}{$H+}
interface
uses
   SysUtils, Forms, StdCtrls, LMessages, Spin, Classes;
type
   { TIntWheelEdit }
   TIntWheelEdit=class(TCustomEdit)
   private
     function GetAsInteger: integer;
   protected
     procedure WMMouseWheel(var Message: TLMMouseEvent); message
LM_MOUSEWHEEL;
     procedure KeyPress(var Key: char); override;
   public
     property AsInteger: integer read GetAsInteger;
   end;
   { TForm1 }
   TForm1 = class(TForm)
     procedure FormCreate(Sender: TObject);
   private
     intEdit: TIntWheelEdit;
     spinEdit: TSpinEdit;
     procedure IntEditChange(Sender: TObject);
   end;
var
   Form1: TForm1;
implementation
{$R *.lfm}

{ TForm1 }

procedure TForm1.FormCreate(Sender: TObject);
begin
   intEdit:=TIntWheelEdit.Create(Self);
   intEdit.Left:=10;
   intEdit.Top:=10;
   ;
   intEdit.TabOrder:=0;
   intEdit.Parent:=Self;
   spinEdit:=TSpinEdit.Create(Self);
   spinEdit.Top:=10;
   spinEdit.Left:=100;
   spinEdit.MinValue:=-1000;
   spinEdit.MaxValue:=1000;
   spinEdit.ReadOnly:=True;
   spinEdit.Parent:=Self;
end;
procedure TForm1.IntEditChange(Sender: TObject);
begin
   if Sender is TIntWheelEdit then
     spinEdit.Value:=TIntWheelEdit(Sender).AsInteger;
end;

{ TIntWheelEdit }

function TIntWheelEdit.GetAsInteger: integer;
begin
   Result:=StrToIntDef(Text, 0);
end;
procedure TIntWheelEdit.WMMouseWheel(var Message: TLMMouseEvent);
var
   i: integer;
begin
   i:=StrToIntDef(Text, 0);
   if Message.WheelDelta >=0 then
     Inc(i)
   else Dec(i);
   Text:=IntToStr(i);
   Message.Result:=1;
end;
procedure TIntWheelEdit.KeyPress(var Key: char);
begin
   case Length(Text)=0 of
     False: if Key in [#8,'0'..'9'] then
              inherited KeyPress(Key)
            else Key:=#0;
     True:  if Key in [#8,'-','0'..'9'] then
              inherited KeyPress(Key)
            else Key := #0;
   end;
end;
end.
===code end===

Reply by email

Timothy Groves
to Howard Page-Clark
Howard Page-Clark wrote 6 lines
On 11/04/2014 19:33, Timothy Groves wrote: > No; I am unsure as to how to do that. Would I need to create a > descendant class, or does Lazarus support overriding without doing so? The following should give you an idea how to develop the hint Mattias gave:

OK, I'll hang onto that in case I need it, but for the tiny little applet I wrote, that's too much effort; it would double the source length easily. :) Thanks.

Reply by email