Recent

Author Topic: How can I disable screen update  (Read 4798 times)

Never

  • Sr. Member
  • ****
  • Posts: 409
  • OS:Win7 64bit / Lazarus 1.4
How can I disable screen update
« on: September 13, 2014, 11:49:57 am »
is there a cross platform function to use and achieve the same result?

Code: [Select]
SendMessage(Handle, WM_SETREDRAW, WPARAM(False), 0);
  try
    // Create  controls
  finally
    // enable updates
    SendMessage(Handle, WM_SETREDRAW, WPARAM(True), 0);
    // Invalidate;  Might  required
  end;

Code: [Select]
.Canvas.Lock; is the way or something else?
« Last Edit: September 13, 2014, 11:56:29 am by Never »
Νέπε Λάζαρε λάγγεψων οξωκά ο φίλοσ'ς αραεύσε

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1252
Re: How can I disable screen update
« Reply #1 on: September 13, 2014, 12:26:37 pm »
I'm using TForm.FormIsUpdating/TForm.BeginFormUpdate/TForm.EndFormUpdate

Code: [Select]
  If Not FormIsUpdating Then
    BeginFormUpdate;     

Code: [Select]
    If FormIsUpdating Then
      EndFormUpdate;   

There's minor issues if you're creating your form dynamically.  Dynamic TToolbars in particular don't like being populated during a FormUpdate. I just needed to be careful with positioning my BeginFormUpdate/EndFormUpdate wraps...
Lazarus Trunk/FPC Trunk on Windows [7, 10]
  Have you tried searching this forum or the wiki?:   http://wiki.lazarus.freepascal.org/Alternative_Main_Page
  BOOKS! (Free and otherwise): http://wiki.lazarus.freepascal.org/Pascal_and_Lazarus_Books_and_Magazines

Never

  • Sr. Member
  • ****
  • Posts: 409
  • OS:Win7 64bit / Lazarus 1.4
Re: How can I disable screen update
« Reply #2 on: September 13, 2014, 01:38:04 pm »
Hello @Mike.Cornflake thank you for your answer
Quote
I'm using TForm.FormIsUpdating/TForm.BeginFormUpdate/TForm.EndFormUpdate

How? TForm does not provide these
if i create a form with the designer  ex[TfrmTest]
 TfrmTest.FormIsUpdating/TfrmTest.BeginFormUpdate/TfrmTest.EndFormUpdate
 these are provided only for the specific form

if  [var x:TForm; x:=TForm.create()] the above are not available
Νέπε Λάζαρε λάγγεψων οξωκά ο φίλοσ'ς αραεύσε

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1252
Re: How can I disable screen update
« Reply #3 on: September 13, 2014, 01:56:34 pm »
Oh, I see.  They're declared protected in TCustomForm, and unfortunately they're not declared virtual.  I've only ever used them inside a form.

If you want to use them from outside your TForm code, then a simple way could be:
Code: [Select]
  TForm1 = class(TForm)
  private
    { private declarations }
  public
    Procedure MyBeginFormUpdate;
    Procedure MyEndFormUpdate;
    Function MyFormIsUpdating: Boolean;
  end;

implementation

procedure TForm1.MyBeginFormUpdate;
begin
  BeginFormUpdate;
end;

procedure TForm1.MyEndFormUpdate;
begin
  EndFormUpdate;
end;

function TForm1.MyFormIsUpdating: Boolean;
begin
  Result := FormIsUpdating;
end;

And then just call the MyXXXX routines from the outside...

(There's probably a better way to widen the scope of the original calls - if so, hopefully others will chime in :) )

UPDATE: Been thinking about this.  Having them declared Protected was a wise design decision.  Essentially what the LCL developers are saying is that only a Form should be responsible for it's own controls/drawing, and that really you should be moving all the code that dynamically creates controls (assuming that's what you're doing) to inside the Form itself.  In light of this, the method I've proposed above, while it will work, should be considered a hack.
« Last Edit: September 13, 2014, 02:01:57 pm by Mike.Cornflake »
Lazarus Trunk/FPC Trunk on Windows [7, 10]
  Have you tried searching this forum or the wiki?:   http://wiki.lazarus.freepascal.org/Alternative_Main_Page
  BOOKS! (Free and otherwise): http://wiki.lazarus.freepascal.org/Pascal_and_Lazarus_Books_and_Magazines

Never

  • Sr. Member
  • ****
  • Posts: 409
  • OS:Win7 64bit / Lazarus 1.4
Re: How can I disable screen update
« Reply #4 on: September 13, 2014, 02:17:23 pm »
i think i will go for
Quote
.Canvas.Lock;
Νέπε Λάζαρε λάγγεψων οξωκά ο φίλοσ'ς αραεύσε

donaldklopper

  • New member
  • *
  • Posts: 5
Re: How can I disable screen update
« Reply #5 on: January 19, 2022, 06:20:44 am »
A couple of years later... I'm on Linux Mint with Lazarus 2.0.6.

SLOW UPDATES: Not locking the form  for update delivers about the same performance as Canvas.Lock and Canvas.Unlock. It's slow.

FASTER UPDATES: Using BeginFormUpdate and EndFormUpdate is SEVERAL ORDERS OF MAGNITUDE faster.

I have a simple little visual CPU killer implemented in a timer event like this:

When the FBounceObjectList size in my example is hundreds of items long the performance difference is extreme.

Code: Pascal  [Select][+][-]
  1.   BeginFormUpdate;
  2.   //Canvas.Lock;
  3.   for i := 0 to FBounceObjectList.Count-1 do
  4.   begin
  5.     TBounceObj(FBounceObjectList[i]).move;
  6.   end;
  7.   //Canvas.Unlock;
  8.   EndFormUpdate;
  9.  

 

TinyPortal © 2005-2018