Mega Code Archive

 
Categories / Delphi / VCL
 

How to freeze a Control

Title: How to freeze a Control Question: sometimes you must freeze a control or the hole form to avaoid flickering. Answer: procedure LockControl(c: TWinControl; lock: boolean); begin if (c = nil) or (c.Handle = 0) then exit; if lock 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; // note: i have found this procedure in a delphi newsgroup; // thanks to the unknown author. (TeamB ?) make shure to use this function in a try ... finally construct or you may see your control never again. example: LockControl(Form1.ListView1, True); try // now work with the ListView1 for i:= 1 to 1000 do Form1.ListView1.Items.Add(..... finally LockControl(Form1.ListView1, False); end;