Title: How to prevent a control from Redrawing (Refreshing)
procedure LockControl(c: TWinControl; bLock: Boolean);
begin
if (c = nil) or (c.Handle = 0) then Exit;
if bLock then
SendMessage(c.Handle, WM_SETREDRAW, 0, 0)
else
begin
SendMessage(c.Handle, WM_SETREDRAW, 1, 0);
RedrawWindow(c.Handle, nil, 0,
RDW_ERASE or RDW_FRAME or RDW_INVALIDATE or RDW_ALLCHILDREN);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
LockControl(DBGrid1, True);
try
// do convoluted things to the grid
finally
LockControl(DBGrid1, False);
end;
end;
A number of controls have a build-in way to do that, the BeginUpdate and
EndUpdate methods. You often find these not on the control itself but on
some object property that manages the controls data, e.g. for a TMemo you use
Lines.BeginUpdate and Lines.EndUpdate. The EndUpdate automatically forces a
redraw of the control.