由于Vcl.Forms.TScrollBox
没有BeginUpdate
/EndUpdate
方法,我使用此代码来减少在作为容器子级的查看器中加载文档时的闪烁TScrollBox
:
procedure MyLockWinControl(const WC: Vcl.Controls.TWinControl; ALock: Boolean);
begin
if (not Assigned(WC)) or (WC.Handle = 0) then EXIT;
if ALock then
WC.Perform(WM_SETREDRAW, 0, 0)
else
begin
WC.Perform(WM_SETREDRAW, 1, 0);
RedrawWindow(WC.Handle, nil, 0, RDW_ERASE or RDW_FRAME or RDW_INVALIDATE or RDW_ALLCHILDREN);
end;
end;
procedure TFormMain.LoadDocFile(const ADocFile: string);
begin
Screen.Cursor := crHourGlass;
try
MyLockWinControl(ScrollBox, True);
try
DoLoadDocFile(ADocFile);
finally
MyLockWinControl(ScrollBox, False);
end;
finally
Screen.Cursor := crDefault;
end;
end;
这很好用,除非在应用程序可重现崩溃的极少数情况下MyLockWinControl(ScrollBox, False);
所以我的问题是: 中是否存在错误MyLockWinControl
,或者是否有更好的方法来停止和恢复更新TScrollBox
?