[Lazarus] TMemo flicker

Michael Van Canneyt michael at freepascal.org
Tue Apr 30 10:06:23 CEST 2013



On Tue, 30 Apr 2013, shoKwave wrote:

> Am 30.04.2013 07:25, schrieb Jürgen Hestermann:
>> Maybe someone can just try my example program.
> OK, now I've tested a bit and BeginUpdate/EndUpdate works for me (Win7 x64, 
> FPC and Laz Trunk):
>
> procedure TForm1.Button1Click(Sender: TObject);
> var i:Integer;
> begin
>  Memo1.Clear;
>  for i := 1 to 40 do
>  begin
>    if odd(i) then
> Memo1.Append('\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\')
>    else
> Memo1.Append('+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++');
>  end;
>
>  for i := 1 to 1000 do
>  begin
>    memo1.Lines.BeginUpdate;
>    Memo1.Lines[Memo1.Lines.Count-1] := '#### LAST LINE 
> ---'+IntToStr(i)+'-----------------------------------------------------------';
>    memo1.Lines.EndUpdate;
>    Application.Processmessages;
>  end;
>  Memo1.Lines[memo1.Lines.Count-1] := '#### READY #### ';
> end;
>

It should be
   memo1.Lines.BeginUpdate;
   for i := 1 to 1000 do
     Memo1.Lines.Add('#### LAST LINE  ---'+IntToStr(i)+'-----------------------------------------------------------');
   memo1.Lines.EndUpdate;
   Application.Processmessages;

What you did makes no sense whatsoever. 
The whole point of beginupdate/endupdate is to mark a list of changes, and to prevent the UI from updating while you do the changes.

The use of Add() is easier to understand.

Michael.


More information about the Lazarus mailing list