如何防止滚动条超出范围?
我使用代码的
procedure TMyCanvas.RichEditChange(Sender: TObject);
var
ScrollInfo: TScrollInfo;
begin
FillChar(ScrollInfo, SizeOF(ScrollInfo), 0);
ScrollInfo.cbSize := SizeOf(ScrollInfo);
ScrollInfo.fMask := SIF_RANGE or SIF_PAGE or SIF_POS;
if GetScrollInfo(FRichEdit.Handle, SB_VERT, ScrollInfo) then
begin
FVertScroll.Max := ScrollInfo.nMax;
FVertScroll.Min := ScrollInfo.nMin;
FVertScroll.PageSize := ScrollInfo.nPage;
FVertScroll.Position := ScrollInfo.nPos;
end;
Invalidate;
end;
问题是,当我添加/删除行时,当我要调整表单大小时,有时会出现错误。它说“滚动条属性超出范围”
我该如何避免它?
谢谢
I use the code
procedure TMyCanvas.RichEditChange(Sender: TObject);
var
ScrollInfo: TScrollInfo;
begin
FillChar(ScrollInfo, SizeOF(ScrollInfo), 0);
ScrollInfo.cbSize := SizeOf(ScrollInfo);
ScrollInfo.fMask := SIF_RANGE or SIF_PAGE or SIF_POS;
if GetScrollInfo(FRichEdit.Handle, SB_VERT, ScrollInfo) then
begin
FVertScroll.Max := ScrollInfo.nMax;
FVertScroll.Min := ScrollInfo.nMin;
FVertScroll.PageSize := ScrollInfo.nPage;
FVertScroll.Position := ScrollInfo.nPos;
end;
Invalidate;
end;
the problem is that when i add/remove lines it gives me error sometimes when im going to resize the form. it says "scrollbar property out of range"
how can i avoid it?
thanx
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我收到此错误消息,发现初始化滚动条时发生了更改,当 PageSize 为 2 时,TScrollbar.Max 被设置为 0。在 Max 为 0 之前将 PageSize 设置为 0 修复了该问题。
I was getting this error message and found that a change had been made when initialising the scrollbar whereby TScrollbar.Max was being set to 0 when PageSize was 2. Setting PageSize to 0 before Max to 0 fixed the issue.
我有另一个奇怪的问题(使用 LargeChange 和 SmallChange),它们被定义为 TScrollBarInc (在 StrCtrls TScrollBar 定义中),并且被定义为 1..32767 (在 Forms
TScrollBarInc = 1..32767;
中)而不是 Integer,而 Min、Max 和 Position 被定义为 Integer(在 StdCtrls TScrollBar 定义上),也在 SetParams 上参数是整数,不是 1..32767。(在我看来)这显然是 TScrollBarInc 类定义上的一个 BUG。
让我举个例子:
需要一个 FIX,类的两个参数(LargeChange 和 SmallChange)的类型覆盖,因此将其类型覆盖为 Integer(与 Min、Max 和 Position 的类型相同)... IDE 帮助说 LargeChange 和 SmallChange 位于 Min & 中。最大范围,但不可能分配 0 和/或任何大于 32767 的值。
如何完成这种“类型覆盖”?编辑:现在我知道,这是在
TForm1 = class(TForm)
之前添加的代码,我的意思是在 interfase 使用之后,在任何类声明之前:现在只需要捕获 OnScroll 并执行通过自己的代码进行滚动,而不是让主要的错误类代码完成这项工作...因为内部 SmallChange & LargeChange 是隐藏的,并且始终具有值 1。
PD:以防万一有人会问,TurboDelphi 2006 ... TTntScrollBar 也受到相同的不匹配类型定义的影响。
I have another weird problem (with LargeChange and SmallChange), they are defined as TScrollBarInc (in StrCtrls TScrollBar definition) and that is defined as 1..32767 (in Forms
TScrollBarInc = 1..32767;
) instead of Integer, while Min, Max and Position are defined as Integer (on StdCtrls TScrollBar definition), also on SetParams the parameters are Integer, not 1..32767.This is (in my oppinion) clearly a BUG on the class definition of TScrollBarInc.
Let me put an example:
It is needed a FIX, a Type Override for that two parameters of the class (LargeChange & SmallChange), so override its type to Integer (same type as Min, Max & Position) ... also the IDE help say that LargeChange and SmallChange are in Min & Max range, but it is imposible to assign 0 and/or any value greater than 32767.
How can this 'type override' be done? EDIT: Now i know, here is the code to add just before
TForm1 = class(TForm)
, i mean just after interfase uses, before any class declaration:Now it is only needed to capture OnScroll and do the scroll by own code, not letting the main buggy class code do the job... since internal SmallChange & LargeChangeare hidden and will allways have value 1.
P.D.: Just in case someone could ask, TurboDelphi 2006 ... also TTntScrollBar is affected by the same missmatch type definitions.
您可以尝试设置
PageSize
属性,并调用SetParams
以避免一一设置各个属性。You could try setting the
PageSize
property, and callingSetParams
to avoid setting individual properties one by one.