Recent

Author Topic: Richmemo.SetTextAttributes is too slow, how could I rise above this issue?  (Read 1987 times)

Tommi

  • Full Member
  • ***
  • Posts: 213
I have this procedure:

Code: [Select]
procedure TForm1.RichMemoApplic();
Var
  tmpNode:PVirtualNode;
  Data: PTreeData;
  aFont:TFontParams;
  versione:TVersions;
  tempo:TDateTime;
  aN:integer=0;
begin
  //exit;   //Troppo lenta
  tempo:=Now;
  tmpNode:=VST.GetFirst();
  while tmpNode<>nil do
  begin
    inc(aN);
    if MilliSecondsBetween(Now,tempo)>2000 then
    begin
      form1.Caption:=inttostr(aN);
      application.ProcessMessages;
      tempo:=Now;
    end;
    Data := VST.GetNodeData(tmpNode);
    if (Data^.num>=0) and (Data^.num<length(versioni)) then
    begin
      if Data^.memoPos>-1 then
      begin
        versione:=versioni[Data^.num];
        if compatibileApplic(selApplic,versione) then
        begin
        //  richmemo1.GetTextAttributes(Data^.memoPos+Data^.memoTabs,aFont);
          aFont.Style:=[];
        //  richmemo1.SetTextAttributes(Data^.memoPos+Data^.memoTabs,Data^.memoLen,aFont);
        end
        else
        begin
      //    richmemo1.GetTextAttributes(Data^.memoPos+Data^.memoTabs,aFont);
          aFont.Style:=[fsStrikeOut];
     //     richmemo1.SetTextAttributes(Data^.memoPos+Data^.memoTabs,Data^.memoLen,aFont);
        end;
      end;
    end;
    tmpNode:=VST.GetNext(tmpNode);
  end;
end;

Commenting the richmemo1.SetTextAttributes and GetTextAttributes the procedure completes in less than one second. If I uncomment those lines the procedure completes in several minutes. The problem is that there are more than 37000 lines in richmemo and every single time it updates the GUI.

I think that if I could update the entire TRichmemo just at the end of the procedure it would be much faster.

Any idea ?

Thank you

rick2691

  • Sr. Member
  • ****
  • Posts: 444
This example might help you...

Code: Pascal  [Select][+][-]
  1. if FileType='.rtf' then // read as native rtf document
  2.             begin
  3.               try PageMemo.Lines.BeginUpdate; // suspends visual update
  4.                   //CleanRTFfile(Diskname);
  5.                   // Utf8ToAnsi below is required for windows stream
  6.                   fs:= TFileStream.Create(Utf8ToAnsi(DiskName), fmOpenRead or fmShareDenyNone);
  7.                   PageMemo.LoadRichText(fs);
  8.                   PageMemo.Hint:= DiskName;
  9.                   finally
  10.                   fs.Free;
  11.                   PageMemo.Lines.EndUpdate; // restores visual update
  12.                   end;
  13.             end;
  14.  

It uses...
PageMemo.Lines.BeginUpdate; // suspends visual update
PageMemo.Lines.EndUpdate; // restores visual update
...at the start and finish of a process.

There are no visual updates until the work is finished.

Rick

Windows 11, LAZ 2.0.10, FPC 3.2.0, SVN 63526, i386-win32-win32/win64, using windows unit

Tommi

  • Full Member
  • ***
  • Posts: 213
Tried, but it's still slow :(

 

TinyPortal © 2005-2018