Recent

Author Topic: [SOLVED] TScrollBox Horizontal Scrollbar Bug?  (Read 15787 times)

knuckles

  • Full Member
  • ***
  • Posts: 122
[SOLVED] TScrollBox Horizontal Scrollbar Bug?
« on: March 27, 2017, 10:31:53 pm »
I have been in the process of making a custom control and noticed something strange which I could not fix and it relates to the horizontal scrollbar range of the TScrollBox and TScrollingWinControl (which I derive my control from).

I can recreate the problem with a simple new project so maybe someone can try this to see if they experience it too and whether or not it is in fact a bug:

Quote
- Create a new project

- Set the form height and width to something like 500.

- Drop a Scrollbox on the form and align to client.

- Drop a control into the scrollbox say a panel or a memo and make the control say 250 in width and height.

Now here is where things get interesting.

Quote
- Set the top value of the control you added to the scrollbox as say 50.

- Run the project and resize the form window from the right to left (make the window smaller) until the horizontal scrollbar appears, now slowly resize the window from left to right (make the window bigger) and notice the scrollbar still visible when it should not be.

- Stop the project and change the top value of the control you added to the scrollbox to 0 and repeat the above, the scrollbar range seems normal.

Im using Lazarus 1.6.4 Win64, FPC 3.0.2 and tested on Windows 10 x64

Ive added some images to help show the problem, can anyone else recreate this and is it a bug?

Thanks
« Last Edit: March 28, 2017, 05:53:30 pm by knuckles »

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: TScrollBox Horizontal Scrollbar Bug?
« Reply #1 on: March 27, 2017, 10:58:51 pm »
A TScrollBox will never work properly if you set its Align to alClient.
If you resize its containing form, you set up conflicting changes affecting the size of the scrollbox itself, and the positioning of its contained controls.
The idea of a scrollbox is that it knows how big it is, and if its contained controls are resized relative to that known size, it can provide internal scrollbars for the user to reposition the resized control.
But if the scrollbox does not know how big it is... how can it determine if scrollbars are needed or not?

knuckles

  • Full Member
  • ***
  • Posts: 122
Re: TScrollBox Horizontal Scrollbar Bug?
« Reply #2 on: March 27, 2017, 11:11:07 pm »
Well I have tested on the latest version of CodeTyphon and Delphi XE7 and they work as expected, but Lazarus is giving incorrect range for some reason.

wp

  • Hero Member
  • *****
  • Posts: 11853
Re: TScrollBox Horizontal Scrollbar Bug?
« Reply #3 on: March 27, 2017, 11:32:28 pm »
Attached project is working correctly with both Laz trunk and Laz 1.6.4 (Win 10). knuckles, you should upload a demo project.

@howardpc: I don't think that this is correct, I've used client-aligned scrollboxes many times. The one thing which must not be done is to client-align the scrollbox content, e.g. the panel within the scrollbox.

knuckles

  • Full Member
  • ***
  • Posts: 122
Re: TScrollBox Horizontal Scrollbar Bug?
« Reply #4 on: March 27, 2017, 11:47:02 pm »
Attached project is working correctly with both Laz trunk and Laz 1.6.4 (Win 10). knuckles, you should upload a demo project.

@howardpc: I don't think that this is correct, I've used client-aligned scrollboxes many times. The one thing which must not be done is to client-align the scrollbox content, e.g. the panel within the scrollbox.

Yes this is true, aligning the scrollbox is perfectly normal, just dont align child controls to the scrollbox client.

Ok I downloaded your project, only changed the memo to left := 0 and the problem still shows for me, I then changed the memo top=0 and the scrollbar works as expected.

Maybe try these changes again and let me know what happens.

Thanks

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: TScrollBox Horizontal Scrollbar Bug?
« Reply #5 on: March 28, 2017, 12:03:22 am »
@wp You're right as usual! Thanks for the correction.

wp

  • Hero Member
  • *****
  • Posts: 11853
Re: TScrollBox Horizontal Scrollbar Bug?
« Reply #6 on: March 28, 2017, 12:13:01 am »
The demo with Laz trunk is fine: In the second phase of the test when the window width increases, the scrollbar disappears when the right edge of the memo becomes visible.

Laz 1.6.4 behaves a little bit differently. Now the horizontal scrollbar is still visible after the right edge of the memo appears. But it disappears when the form width and memo width differ by the width of the (invisible) vertical scrollbar.

If you decrese the height of the window such that the vertical scrollbar is visible and repeat the experiment the horizontal scrollbar behaves correctly.

Therefore, I'd say that Laz 1.6.4 does not correctly consider the width of the vertical scrollbar. Evidently, this has been fixed in the meantime.

knuckles

  • Full Member
  • ***
  • Posts: 122
Re: TScrollBox Horizontal Scrollbar Bug?
« Reply #7 on: March 28, 2017, 12:20:53 am »
@wp Glad you can see it and yeah I actually thought it was somehow using the invisible vertical scrollbar in some way, very strange behavior. It would be interesting to see if there are any patch notes or something to see what changed or what fixed it out of curiosity.

Anyway I will now download and test with a Lazarus trunk version too.

Thanks

knuckles

  • Full Member
  • ***
  • Posts: 122
Re: TScrollBox Horizontal Scrollbar Bug?
« Reply #8 on: March 28, 2017, 12:40:16 am »
The bug also seems present in 1.6.2, never downloaded from the trunk before so will try and work out how to do that now...

wp

  • Hero Member
  • *****
  • Posts: 11853
Re: TScrollBox Horizontal Scrollbar Bug?
« Reply #9 on: March 28, 2017, 12:40:35 am »
I checked other Lazarus versions, even 1.4.4 has it (I did not go back any further).

I scanned the svn commit notes, and found this one: r51640 "lcl: fix wrong scrollbar height calculation". It adds a method TControlScrollbar.ControlSize (in forms.pp):

Code: Pascal  [Select][+][-]
  1. function TControlScrollBar.ControlSize: integer;
  2. begin
  3.   if Kind = sbVertical then
  4.     Result := FControl.Width
  5.   else
  6.     Result := FControl.Height;
  7. end;

And this is called in
Code: Pascal  [Select][+][-]
  1. function TControlScrollBar.ClientSizeWithoutBar: integer;
  2. begin
  3.   Result:=ClientSize;
  4.   if IsScrollBarVisible then
  5.     Result := Min(ControlSize, Result+GetSize+GetSystemMetrics(SM_SWSCROLLBARSPACING));
  6. end;

If you apply these modification to 1.6.4 there's a good chance that it will fix the issue (I did not do it myself).

knuckles

  • Full Member
  • ***
  • Posts: 122
Re: TScrollBox Horizontal Scrollbar Bug?
« Reply #10 on: March 28, 2017, 12:43:12 am »
Good spotting @wp, I will try and patch 1.6.4 first rather than download from svn trunk...

knuckles

  • Full Member
  • ***
  • Posts: 122
Re: TScrollBox Horizontal Scrollbar Bug?
« Reply #11 on: March 28, 2017, 05:53:08 pm »
Dam I spent too much time trying to install trunk from svn (not easy for beginners like me who never use svn etc).

Anyway I got Lazarus 1.7 and FPC 3.1.1 working by installing from https://www.getlazarus.org/setup/ but this also does not include the fix, so to patch it you need to edit controlscrollbar.inc and change function TControlScrollBar.ClientSizeWithoutBar like so:

Quote
function TControlScrollBar.ClientSizeWithoutBar: integer;
var
   ControlSize: Integer;
begin
   if Kind = sbVertical then
    ControlSize := FControl.Width
  else
    ControlSize := FControl.Height;

  Result:=ClientSize;
  if IsScrollBarVisible then
    Result := Min(ControlSize, Result+GetSize+GetSystemMetrics(SM_SWSCROLLBARSPACING));
end;

Done a few quick tests and this seems to be working ok.

Many thanks @wp  :)

wp

  • Hero Member
  • *****
  • Posts: 11853
Re: TScrollBox Horizontal Scrollbar Bug?
« Reply #12 on: March 28, 2017, 08:02:26 pm »
Dam I spent too much time trying to install trunk from svn (not easy for beginners like me who never use svn etc).
I think you are on Windows:
  • Install TortoiseSVN
  • Install Lazarus 1.6.4 into a folder which later should contain Lazarus trunk. Name the folder, say, c:\laztrunk. Choose "Secondary installation" and enter a name for the folder to be the home of Lazarus settings. Use a folder name different from that where your current Lazarus stores its settings. Do not register any file extensions. These precautions are made to leave the settings of your current Lazarus version untouched.
  • Since TortoiseSVN wants an empty folder for the initial checkout rename c:\laztrunk to c:\laztrunk_temp when the installation is complete. Recreate c:\laztrunk - this is empty, of course.
  • Right-click on it, select "SVN Checkout". In "URL of repository" enter http://svn.freepascal.org/svn/lazarus/trunk. The rest should be correct. "OK" copies all the trunk source files into the new folder. But the fpc binaries, configuration files etc are still missing.
  • To get them copy the fpc and mingw folder trees, as well as all files in the installation root from c:\laztrunk_temp to c:\laztrunk. Since Laz 1.6.4 and fpc were installed in c:\laztrunk all the paths are correct.
  • Delete c:\laztrunk_temp -- we don't need it any more
  • Start Lazarus from c:\laztrunk (it is still v1.6.4). There may be an error message about missing sources. Make sure that the source folder is specified as c:\laztrunk. Ignore other error messages.
  • Rebuild the IDE from the trunk sources ("Tools" > "Build Lazarus with Profile..."). This may take some time. After the IDE has restarted you are ready to go (at the first start, you are prompted to upgrade your settings to the new version -- "OK"; note this leaves your other Lazarus installation alone).
  • If you later want to update the trunk revision simply right-click on c:\laztrunk and select "SVN Update". This replaces all the source files that were changed in the meantime. Usually that's all, Lazarus will recompile everything needed. But if there were some changes in the IDE itself then you must rebuild the IDE again as you did after the initial checkout. In particular, if you did not have to rebuild the IDE, this is a matter of a few seconds -- much faster than fpcupdeluxe which is another easy way to get Laz trunk.
  • If you want to see what was changed between your revision and the repository revision right-click on "TortoiseSVN"and select "SVN Show log". Now you get a list of all commit messages of the developers. Your current revision is highlighted in bold type-face. Everything above the bold line is new.
  • If you want to get rid of trunk simply delete c:\laztrunk and the settings folder.

knuckles

  • Full Member
  • ***
  • Posts: 122
Re: [SOLVED] TScrollBox Horizontal Scrollbar Bug?
« Reply #13 on: March 28, 2017, 11:32:23 pm »
Great thanks wp,

I was trying to follow the wiki help pages and got as far as able to download the lazarus and fpc sources through the svn but couldnt figure out how to build anything and generate the exe's, this might prove helpful in future if I want to try again.

shuklasa

  • Newbie
  • Posts: 4
Re: [SOLVED] TScrollBox Horizontal Scrollbar Bug?
« Reply #14 on: April 04, 2017, 01:59:07 pm »
Thank you very much. I applied this patch to 1.6 and Issues was solved.

 

TinyPortal © 2005-2018