procedure TCustomScrollBar.SetParams(APosition, AMin, AMax, APageSize: Integer);
var
ScrollInfo: TScrollInfo;
lEnabled : boolean;
lfMask : UINT = 0;
begin
if AMax < AMin then
raise EInvalidOperation.Create(rsScrollBarOutOfRange);
{ Test if SetParams was called thru a .SetPosition, before eventual adjustment }
if (FPosition <> APosition) then
lfMask := lfMask or SIF_POS;
{ Check position within range }
if APosition < AMin then APosition := AMin;
if APosition > AMax then APosition := AMax;
if APageSize < 0 then APageSize := 0;
{ Test values that changed }
if (FMin <> AMin) then begin
FMin := AMin;
lfMask := lfMask or SIF_Range;
end;
if (FMax <> AMax) then begin
FMax := AMax;
lfMask := lfMask or SIF_Range;
end;
if (lfMask and SIF_POS)<>0 then begin // Only if position change requested
if not NotRightToLeft then // Review this code for correctness
APosition := FMax - APosition;
FPosition := APosition;
end;
if (FPageSize <> APageSize) then begin // ? problem if APageSize > (max-min) ?
lfMask := lfMask or SIF_Range;
FPageSize := APageSize;
end;
if HandleAllocated then begin
lEnabled := IsWindowEnabled(Handle); // Dont use IsEnabled, because Form could
// be disabled due to form Disabled.
if ((lfMask and (SIF_PAGE or SIF_Range or SIF_POS))<>0) then begin
ScrollInfo.fMask := lfMask;
ScrollInfo.nMin := AMin;
ScrollInfo.nMax := AMax;
ScrollInfo.nPos := APosition;
ScrollInfo.nPage := APageSize;
APosition := SetScrollInfo(Handle, SB_CTL, ScrollInfo, lEnabled);
{ Was position changed as a consequence of SetScrollInfo }
if (APosition<>FPosition) then begin
if ((lfMask and SIF_POS) = 0) then // SIF_POS not requested, Ping-Pong
Position := APosition // actualisation of Position to force .Change
else begin // Ajust FPosition to new position
if not NotRightToLeft then // Review this code for correctness
APosition := FMax - APosition;
FPosition := APosition;
end;
end;
end;
end;
{~bk not needed in windows, qt5}
{$IF not defined(LCLWin32) and not defined(LCLQT)}
if (FPosition <> APosition) then begin
if HandleAllocated then begin
ScrollInfo.fMask := SIF_POS;
if NotRightToLeft then
ScrollInfo.nPos := APosition
else
ScrollInfo.nPos := FMax - FPosition;
FPosition := SetScrollInfo(Handle, SB_CTL, ScrollInfo, lEnabled);
end
else
FPosition := APosition;
end;
if HandleAllocated then
TWSScrollBarClass(WidgetSetClass).SetParams(Self);
{$ENDIF}
end;