Solved

Loading large file in a TRichEdit

Posted on 2014-04-08
9
385 Views
Last Modified: 2014-04-09
Hi all this question is related this one: http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_28407456.html#a39986818

I thought the problem was the StringList but the bottleneck is TRichEdit. The file is very fastly loaded in the StringList but it takes a long time to be loaded in TRichEdit and when it is loaded it freezes the program. I use TRichEdit because I have a piece of code which allows me to use a different font color for certain words.
In my case, I highlight all non existent paths to allow the user to edit them accordingly to his system.

How can solve this problem?
Thanks in advance
Marco
0
Comment
Question by:Marco Gasi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 45

Accepted Solution

by:
aikimark earned 500 total points
ID: 39987055
I can offer this work-around.  Use a listbox control and use custom drawing to do your highlighting.  When the user clicks on a listbox item, you move that selected item into an edit control.  Update the listbox item after the user has finished editing.

a code example is in this article:
http://delphi.about.com/cs/adptips2002/a/bltip0602_4.htm
0
 
LVL 31

Author Comment

by:Marco Gasi
ID: 39987167
Okay, aikimark, Listbox is very fast! But I still have an issue with the OwnerDraw event. Here's my code:

procedure TfrmIncorrectPaths.lbxRegFileDrawItem(Control: TWinControl;
  Index: Integer; Rect: TRect; State: TOwnerDrawState);
var
  myColor: TColor;
  myBrush: TBrush;
  rx: TPerlRegEx;
  I: Integer;
begin
  myBrush := TBrush.Create;
  try
    rx := TPerlRegEx.Create;
    try
      with (Control as TListBox).Canvas do
      begin
          rx.Options := [preCaseLess,preExtended];
          rx.RegEx := '\b[a-z]:\\                    # Drive'#10 +
                      '(?:[^\\/:*?"<>|\r\n]+\\)*     # Folder'#10 +
                      '[^\\/:*?"<>|\r\n]*            # File';
          rx.Subject := lbxRegFile.Items[Index];
          if rx.Match then
          begin
            if (not DirectoryExists(ExtractFilePath(rx.MatchedText))) then
              myColor := clYellow
            else
              myColor := clWhite;
          end;
        myBrush.Style := bsSolid;
        myBrush.Color := myColor;
        Winapi.Windows.FillRect(handle, Rect, myBrush.Handle) ;
        Brush.Style := bsClear;
        TextOut(Rect.Left, Rect.Top,
                 (Control as TListBox).Items[Index]) ;
      end;
    finally
      rx.Free;
    end;
  finally
    MyBrush.Free;
  end;
end;

Open in new window


It correctly draws a yellow background for non existent directories (it highlights the whole item instead of the directory string only but I can accept it), but all the rest is black! It's sure because I don't understand brush tecniques: can you help me?
0
 
LVL 45

Expert Comment

by:aikimark
ID: 39987339
The only difference I notice between your code and the article's code is
Winapi.Windows.FillRect()
vs.
Windows.FillRect()

What version of Delphi are you using?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 31

Author Comment

by:Marco Gasi
ID: 39987846
XE3. If I only use Windows.FillRect I get 'Undeclared identifier: Windows' error when I try to compile.
0
 
LVL 31

Author Comment

by:Marco Gasi
ID: 39987918
Solved. The working code is the following:

procedure TfrmIncorrectPaths.lbxRegFileDrawItem(Control: TWinControl;
  Index: Integer; Rect: TRect; State: TOwnerDrawState);
var
  myColor: TColor;
  myBrush: TBrush;
  rx: TPerlRegEx;
  I: Integer;
begin
  myBrush := TBrush.Create;
  try
    rx := TPerlRegEx.Create;
    try
      rx.Options := [preCaseLess,preExtended];
      rx.RegEx := '\b[a-z]:\\                    # Drive'#10 +
                  '(?:[^\\/:*?"<>|\r\n]+\\)*     # Folder'#10 +
                  '[^\\/:*?"<>|\r\n]*            # File';
      rx.Subject := lbxRegFile.Items[Index];
      if rx.Match then
      begin
        if (not DirectoryExists(ExtractFilePath(rx.MatchedText))) then
          myColor := clYellow
        else
          myColor := clWhite;
      end
      else
        myColor := clWhite;
      with (Control as TListBox).Canvas do
      begin
        myBrush.Style := bsSolid;
        myBrush.Color := myColor;
        Winapi.Windows.FillRect(handle, Rect, myBrush.Handle) ;
        Brush.Style := bsClear;
        TextOut(Rect.Left, Rect.Top,
                 (Control as TListBox).Items[Index]) ;
      end;
    finally
      rx.Free;
    end;
  finally
    MyBrush.Free;
  end;
end;

Open in new window


Thanks
0
 
LVL 31

Author Closing Comment

by:Marco Gasi
ID: 39987919
Thank you so mutch!
0
 
LVL 45

Expert Comment

by:aikimark
ID: 39988447
You're welcome.

Ah.  I see the problem now as well.  Thanks for posting the fixed/correct code. I missed the default white color being lost.  Maybe it is only a style difference, but you might try the following structure to see if it is faster than the else clause.
      myColor := clWhite;
      if rx.Match then
        if (not DirectoryExists(ExtractFilePath(rx.MatchedText))) then
          myColor := clYellow;

Open in new window

0
 
LVL 45

Expert Comment

by:aikimark
ID: 39988471
Note: I edited my comment, tweaking the code for simplicity.
0
 
LVL 31

Author Comment

by:Marco Gasi
ID: 39988581
Okay, I'll try it. Yhank you for this further help. Please, if you can take a look at the other quesiton: http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_28408505.html
Cheers
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question