03 July, 2013

Mouse wheel behaves strangely with dbgrids ( pindah record pake scroll mouse )

this code handler will correct this behavior.

Paste code dibawah ini pada public declaration :
procedure AppMessage(var Msg: TMsg; var Handled: Boolean);

Paste code dibawah ini dibawah impelentasi : ( TForm1 Sesuaikan dengan nama form kerja contoh : TMenu_Utama )

procedure TForm1.AppMessage(var Msg: TMsg; var Handled: Boolean);
var
a: Smallint;
begin
if Msg.message = WM_MOUSEWHEEL then
begin
Msg.message := WM_KEYDOWN;
Msg.lParam := 0;
a := HiWord(Msg.wParam);
if a > 0 then
Msg.wParam := VK_UP else
Msg.wParam := VK_DOWN;
Handled := False;
end;
end;


View Unit ( CTRL + F12 ). dan pilih project1 (sesuaikan dengan nama projek )
Paste code berikut

Application.OnMessage :=Form13.AppMessage;
Application.Run; // ini sudah ada pada coding. yg dipaste hanya 1 baris diatas.

original http://delphi.about.com/cs/adptips2002/a/bltip1102_3.htm


Just drop a TApplicationEvents ("Additional" tab on the Component Palette) component on a form and handle it's OnMessage event as:
~~~~~~~~~~~~~~~~~~~~~~~~~
procedure TForm1.ApplicationEvents1Message
   (var Msg: TMsg; var Handled: Boolean) ;
var
   i: SmallInt;
begin
   if Msg.message = WM_MOUSEWHEEL then
   begin
     Msg.message := WM_KEYDOWN;
     Msg.lParam := 0;
     i := HiWord(Msg.wParam) ;
     if i > 0 then
       Msg.wParam := VK_UP
     else
       Msg.wParam := VK_DOWN;

     Handled := False;
   end;
end;
~~~~~~~~~~~~~~~~~~~~~~~~~

Note: This fixes the mouse wheel behavior not only for DBGrid-s but for all other list component (TListBox, TListView, etc).