Recent

Author Topic: TScrollbox limit?  (Read 3715 times)

The Learner

  • Newbie
  • Posts: 6
TScrollbox limit?
« on: June 17, 2018, 04:10:22 pm »
Sorry for my English. I'm not use English as my Primary language.

I had a problem with scrollbox with my developing program.
So I done a test by create new project.
drop a scrollbox, a panel and a button
Code: Pascal  [Select][+][-]
  1. { TForm1 }
  2. const
  3.   max = 100;
  4.  
  5. var
  6.   i,Atop, Awidth, Aheight: integer;
  7.   pn : array[0..max] of tImage;
  8.  
  9. procedure TForm1.FormCreate(Sender: TObject);
  10. begin
  11.   scrollbox1.Align := alClient;
  12.   scrollbox1.VertScrollBar.Increment := 200;
  13.   for i := 0 to max do begin
  14.     pn[i] := tImage.create(scrollbox1);
  15.     pn[i].Center := True;
  16.     pn[i].AutoSize := False;
  17.     pn[i].Parent := Scrollbox1;
  18.   end;
  19. end;
  20.  
  21. procedure TForm1.ScrollBox1Paint(Sender: TObject);
  22. begin
  23.   panel1.Caption := inttostr(scrollbox1.VertScrollBar.Position);
  24. end;
  25.  
  26. procedure TForm1.Button1Click(Sender: TObject);
  27. begin
  28.   button1.Enabled := False;
  29.   Atop := 0; Awidth := scrollbox1.ClientWidth; Aheight := 1100;
  30.   for i := 0 to max do begin
  31.     //    pn[i].SetBounds(0,Atop,Awidth,Aheight);
  32.     pn[i].Top := Atop;
  33.     pn[i].Left := 0;
  34.     pn[i].Width := Awidth;
  35.     pn[i].Height := Aheight;
  36.     if i = 0 then pn[i].Picture.LoadFromFile('testPic.jpg')
  37.     else pn[i].Picture := pn[i-1].Picture;
  38.     inc(Atop,Aheight+10);
  39.   end;
  40. end;
  41.  
  42. end.
  43.  

When I scroll with mouse wheel pass the position of 65535.
scrollbox position will jump back to 0.
'testpic.jpg' size is 750x1100.

I don't know that I miss/mess somethings/ or is this scrollbox limit or bug?
and Please suggest me how to avoid this.

Thanks.


lainz

  • Hero Member
  • *****
  • Posts: 4460
    • https://lainz.github.io/
Re: TScrollbox limit?
« Reply #1 on: June 17, 2018, 04:49:23 pm »
Yes, it's a limit. I had the same problem before, putting a lot of controls inside a panel or form, reaching the limit of height on Windows.

The Learner

  • Newbie
  • Posts: 6
Re: TScrollbox limit?
« Reply #2 on: June 17, 2018, 05:09:20 pm »
Oh! it's so. I want to make a program to load all image from a folder at once (manga) and read by just scrolling down.
I'd saw some program can do this but I don't like some features and it's interface.
So, How can I solve this problem.
I'd ever tried Drawgrid and the result is awful. (not test about limit too)

Handoko

  • Hero Member
  • *****
  • Posts: 5129
  • My goal: build my own game engine using Lazarus
Re: TScrollbox limit?
« Reply #3 on: June 18, 2018, 10:40:39 am »
On my tests, it started to show problem when the Top > 32767. Here is the modified code, which only 1 image can be shown:

Code: Pascal  [Select][+][-]
  1. const
  2.   max = 1;
  3.  
  4. procedure TForm1.Button1Click(Sender: TObject);
  5. begin
  6.   button1.Enabled := False;
  7.   Atop := 32000; Awidth := scrollbox1.ClientWidth; Aheight := 1100;
  8.   for i := 0 to max do begin
  9.     pn[i].Top := Atop;
  10.     pn[i].Left := 0;
  11.     pn[i].Width := Awidth;
  12.     pn[i].Height := Aheight;
  13.     if i = 0 then pn[i].Picture.LoadFromFile('a.jpg')
  14.     else pn[i].Picture := pn[i-1].Picture;
  15.     inc(Atop,Aheight+10);
  16.   end;
  17. end;

Because max = 1, it should show 2 images. But I only got 1 image, the second image (Atop = 33110) was missing and I can only saw blank space. If I set the starting value Atop := 30000, all work correctly. The second image started to show problem if Atop > 32767. That number is max value of Smallint.

Tested on Ubuntu Mate 18.04 Lazarus 1.8.4 64-bit Gtk2.

Please submit a bug report here:
https://bugs.freepascal.org

Below is the source code I used, if anyone interested.

---edited---
I re-uploaded the correct code.
« Last Edit: June 18, 2018, 01:03:37 pm by Handoko »

The Learner

  • Newbie
  • Posts: 6
Re: TScrollbox limit?
« Reply #4 on: June 18, 2018, 11:23:16 am »
OS: Windows 7
found no problem when try your code [Handoko]

Handoko

  • Hero Member
  • *****
  • Posts: 5129
  • My goal: build my own game engine using Lazarus
Re: TScrollbox limit?
« Reply #5 on: June 18, 2018, 01:02:23 pm »
Oops, I uploaded the wrong code. The correct one should have:
Code: Pascal  [Select][+][-]
  1.   Atop := 32000;

I re-uploaded the code again. Now, you should see only 1 picture and then blank space. At least that happened on Linux system.

The Learner

  • Newbie
  • Posts: 6
Re: TScrollbox limit?
« Reply #6 on: June 18, 2018, 01:26:13 pm »
No. I didn't load your .zip file. just change in my source code.
For Windows base. no problem of 32767
My problem is only for mouse wheel scroll pass 65535 points.
If I'd use mouse to drag Vertical scroll bar, there's no issue.

And I'd forgot the big things.
BIG Thank for your replies.  :D

Handoko

  • Hero Member
  • *****
  • Posts: 5129
  • My goal: build my own game engine using Lazarus
Re: TScrollbox limit?
« Reply #7 on: June 18, 2018, 01:32:30 pm »
The behavior is different on Linux. The limit is 32767 and the issue always happens both on using mouse wheel and mouse dragging on vertical scroll bar.

The Learner

  • Newbie
  • Posts: 6
Re: TScrollbox limit?
« Reply #8 on: June 18, 2018, 02:45:58 pm »
lol, that's mean 'Write Once, Compile Anywhere(with some corrections)'  :D

The Learner

  • Newbie
  • Posts: 6
Re: TScrollbox limit?
« Reply #9 on: June 20, 2018, 01:16:16 am »
These are 'Quick and Dirty' way that I solve this problem.
Code: Pascal  [Select][+][-]
  1. procedure TForm1.ScrollBox1MouseWheelDown(Sender: TObject; Shift: TShiftState;
  2.   MousePos: TPoint; var Handled: Boolean);
  3. var
  4.   scP, scI : Integer;
  5. begin
  6.   scP := ScrollBox1.VertScrollBar.Position;
  7.   scI := ScrollBox1.VertScrollBar.Increment;
  8.   if ( scP < 65535) and (scP + scI > 65535) then
  9.     ScrollBox1.VertScrollBar.Position := scP + scI;
  10. end;
  11.  
  12. procedure TForm1.ScrollBox1MouseWheelUp(Sender: TObject; Shift: TShiftState;
  13.   MousePos: TPoint; var Handled: Boolean);
  14. var
  15.   scP, scI : Integer;
  16. begin
  17.   scP := ScrollBox1.VertScrollBar.Position;
  18.   scI := ScrollBox1.VertScrollBar.Increment;
  19.   if (scP > 65535) and (scP - scI < 65535 ) then
  20.   ScrollBox1.VertScrollBar.Position := scP - scI;
  21. end;
  22.  
And the result is: It's WORK!
 O:-)
« Last Edit: June 20, 2018, 01:19:26 am by The Learner »

 

TinyPortal © 2005-2018