Recent

Author Topic: Scrollbox with OnScroll Event.  (Read 4330 times)

hosune7845

  • Full Member
  • ***
  • Posts: 159
Scrollbox with OnScroll Event.
« on: February 17, 2016, 06:03:50 am »
Hi.

I tried to use OnScroll with TScrollBox.

So, I modified some codes.

But ScrollBar doesn't move from position=0

Here's my code :
in Forms.pp
Code: Pascal  [Select][+][-]
  1. ...
  2.   TScrollExEvent = procedure(Sender: TObject; var ScrollPos: Integer) of object;
  3.   TScrollBox = class(TScrollingWinControl)
  4.   //Modified
  5.   strict private
  6.     FOnVScroll: TScrollExEvent;
  7.     FOnHScroll: TScrollExEvent;
  8.   //
  9.   protected
  10.     //Modified
  11.     procedure WMHScroll(var Message : TLMHScroll); message LM_HScroll;
  12.     procedure WMVScroll(var Message : TLMVScroll); message LM_VScroll;
  13.     procedure DoHScroll(var aScrollPos: integer);
  14.     procedure DoVScroll(var aScrollPos: integer);
  15.     //
  16.     class procedure WSRegisterClass; override;
  17.   public
  18.     constructor Create(AOwner: TComponent); override;
  19.   published
  20.     //Modified
  21.     property OnVScroll: TScrollExEvent read FOnVScroll write FOnVScroll;
  22.     property OnHScroll: TScrollExEvent read FOnHScroll write FOnHScroll;
  23.     //    
  24. ....                          
  25.  

In Scrollbox.inc
Code: Pascal  [Select][+][-]
  1. ...
  2. //Modified
  3. procedure TScrollBox.DoHScroll(var aScrollPos: integer);
  4. begin
  5.   if Assigned(FOnHScroll) then
  6.     FOnHScroll(Self, aScrollPos);
  7. end;
  8.  
  9. procedure TScrollBox.DoVScroll(var aScrollPos: integer);
  10. begin
  11.   if Assigned(FOnVScroll) then
  12.     FOnVScroll(Self, aScrollPos);
  13. end;
  14.  
  15. procedure TScrollBox.WMHScroll(var Message: TLMHScroll);
  16. begin
  17.   HorzScrollBar.Position:=Message.Pos;
  18.   DoHScroll(Message.Pos);
  19. end;
  20.  
  21. procedure TScrollBox.WMVScroll(var Message: TLMVScroll);
  22. begin
  23.   VertScrollbar.Position:=Message.Pos;
  24.   DoVScroll(Message.Pos);
  25. end;
  26. //
  27. ...
  28.  

My Main unit
Code: Pascal  [Select][+][-]
  1. ...
  2. type
  3.  
  4.   { TForm1 }
  5.  
  6.   TForm1 = class(TForm)
  7.     Image1: TImage; //In ScrollBox1
  8.     Memo1: TMemo;
  9.     ScrollBox1: TScrollBox;
  10.     procedure FormCreate(Sender: TObject);
  11.   private
  12.     procedure HandleH(Sender: TObject; var ScrollPos: Integer);
  13.     procedure HandleV(Sender: TObject; var ScrollPos: Integer);
  14.     { private declarations }
  15.   public
  16.     { public declarations }
  17.   end;
  18.  
  19. var
  20.   Form1: TForm1;
  21.  
  22. implementation
  23.  
  24. {$R *.lfm}
  25.  
  26. { TForm1 }
  27.  
  28. procedure TForm1.FormCreate(Sender: TObject);
  29. begin
  30.   ScrollBox1.OnHScroll := @HandleH;
  31.   ScrollBox1.OnVScroll := @HandleV;
  32. end;
  33.  
  34. procedure TForm1.HandleH(Sender: TObject; var ScrollPos: Integer);
  35. begin
  36.   Memo1.Lines.Add('H : ' + inttostr(ScrollPos));
  37. end;
  38.  
  39. procedure TForm1.HandleV(Sender: TObject; var ScrollPos: Integer);
  40. begin
  41.   Memo1.Lines.Add('V : ' + inttostr(ScrollPos));
  42. end;  
  43.  

balazsszekely

  • Guest
Re: Scrollbox with OnScroll Event.
« Reply #1 on: February 17, 2016, 07:12:35 am »
It works fine: https://youtu.be/WDStil_r2i8
By the way, I believe something similar should be implemented in the trunk.

hosune7845

  • Full Member
  • ***
  • Posts: 159
Re: Scrollbox with OnScroll Event.
« Reply #2 on: February 19, 2016, 08:04:24 am »
It works fine: https://youtu.be/WDStil_r2i8
By the way, I believe something similar should be implemented in the trunk.

Thank you.

But, I've solved with TTimer  :(

knuckles

  • Full Member
  • ***
  • Posts: 122
Re: Scrollbox with OnScroll Event.
« Reply #3 on: May 05, 2016, 07:36:58 pm »
Old post I know, anyway just for reference the reason your scrollbar was sticking at 0 position is because you likely forgot to add inherited to the scroll message.

 

TinyPortal © 2005-2018