VertScrollBar.Visible always returns TRUE
I have a custom control derived from TScrollBox. At run time, I need to know weather the vertical scrollbar is visible or not. If I interrogate the Visible property it always returns true, no matter if the scrollbar is visible or not!
function TMyScrollPanel.ScrollVisible: boolean; begin Result:= Self.VertScrollBar.Visible; <----------- always true end;
However, this works correctly:
function VertScrollBarVisible(WindowHandle: THandle): Boolean; begin Result:= (GetWindowlong(WindowHandle, GWL_STYLE) AND WS_VSCROLL) <> 0 end;
What is wrong with the first function?
Reading a scrollbar Visible property only retrives VCL control state. The property won't retrieve the current state from the actual scrollbar window. Use the IsScrollBarVisible property instead.
Use the IsScrollBarVisible method instead, to check whether a scrollbar is visible because the scrollable window can be scrolled.
Reading the Visible property only retrieves the cached value of its visibility setting (can be visible or not). For a scrollable window, the property won't retrieve the current state from the actual window.