Recent

Author Topic: MouseWheelDown compiler error in other unit  (Read 510 times)

yazigegeda

  • New Member
  • *
  • Posts: 29
MouseWheelDown compiler error in other unit
« on: May 16, 2024, 01:39:17 pm »
Unit1:

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ComCtrls, Types;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     ListView1: TListView;
  16.     procedure FormCreate(Sender: TObject);
  17.     procedure ListView1MouseWheelDown(Sender: TObject; Shift: TShiftState;
  18.       MousePos: TPoint; var Handled: Boolean);
  19.   private
  20.  
  21.   public
  22.  
  23.   end;
  24.  
  25. var
  26.   Form1: TForm1;
  27.  
  28. implementation
  29.  
  30. uses
  31.   Unit2;
  32.  
  33. {$R *.lfm}
  34.  
  35. { TForm1 }
  36.  
  37. procedure TForm1.FormCreate(Sender: TObject);
  38. begin
  39.  
  40.  
  41.    ListView1.OnMouseWheelDown:=@Unit2.TForm2.ListView1MouseWheelDown;
  42. end;
  43.  
  44.  
  45. end.
  46.  


Unit2:

Code: Pascal  [Select][+][-]
  1. unit Unit2;
  2.  
  3. {$mode ObjFPC}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs;
  9.  
  10. type
  11.  
  12.   { TForm2 }
  13.  
  14.   TForm2 = class(TForm)
  15.   private
  16.  
  17.   public
  18.  
  19.     procedure ListView1MouseWheelDown(Sender: TObject; Shift: TShiftState;
  20.   MousePos: TPoint; var Handled: Boolean);
  21.  
  22.   end;
  23.  
  24. procedure pro;
  25.  
  26. var
  27.   Form2: TForm2;
  28.  
  29. implementation
  30.  
  31. procedure pro;
  32. begin
  33.  
  34. end;
  35.  
  36. {$R *.lfm}
  37.  
  38. { TForm2 }
  39.  
  40. procedure TForm2.ListView1MouseWheelDown(Sender: TObject; Shift: TShiftState;
  41.   MousePos: TPoint; var Handled: Boolean);
  42. begin
  43.  
  44. end;
  45.  
  46. end.
  47.  


Compilation error:
Code: Pascal  [Select][+][-]
  1. unit1.pas(41,32) Error: Incompatible types: got "<address of procedure(TObject;TShiftState;TPoint;var Boolean) of object;Register>" expected "<procedure variable type of procedure(TObject;TShiftState;TPoint;var Boolean) of object;Register>"


I want to put the listview MouseWheelDown event in another unit, but how do I handle the compilation error :'(

« Last Edit: May 16, 2024, 01:40:48 pm by yazigegeda »

Fibonacci

  • Sr. Member
  • ****
  • Posts: 446
  • Internal Error Hunter
Re: MouseWheelDown compiler error in other unit
« Reply #1 on: May 16, 2024, 01:41:41 pm »
Line 41

Code: Pascal  [Select][+][-]
  1. ListView1.OnMouseWheelDown:=@Unit2.TForm2.ListView1MouseWheelDown;

Change to

Code: Pascal  [Select][+][-]
  1. ListView1.OnMouseWheelDown:=@Unit2.Form2.ListView1MouseWheelDown;

yazigegeda

  • New Member
  • *
  • Posts: 29
Re: MouseWheelDown compiler error in other unit
« Reply #2 on: May 17, 2024, 04:14:31 am »
Line 41

Code: Pascal  [Select][+][-]
  1. ListView1.OnMouseWheelDown:=@Unit2.TForm2.ListView1MouseWheelDown;

Change to

Code: Pascal  [Select][+][-]
  1. ListView1.OnMouseWheelDown:=@Unit2.Form2.ListView1MouseWheelDown;


Thank you for his success! :-*

 

TinyPortal © 2005-2018