?
Solved

Loading large file in a TRichEdit

Posted on 2014-04-08
9
Medium Priority
?
392 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 46

Accepted Solution

by:
aikimark earned 2000 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 46

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 46

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 46

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

777 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