Solved

How do I override TRichEdit.Lines.Add ?

Posted on 2011-02-10
6
400 Views
Last Modified: 2012-05-11
I need to override TRichEdit.Lines.Add in order to do some processing there, before adding the text in the RichEdit. How can I do that? Can I do that directly?
0
Comment
Question by:cubic77
  • 3
  • 3
6 Comments
 
LVL 32

Expert Comment

by:ewangoya
Comment Utility

Not exactly, the TStrings.Add method itself can be overriden but TRichEdit is not structured in such a way to allow you to do that easily

you can go around it by using the code as follows in your form unit
type
  TRichEdit = class(ComCtrls.TRichEdit)
  public
    function Add(const AString: string): Integer; 
  end;
  
  TForm1 = class(TForm)
    ............
  end;

implementation

function TRichEdit.Add(const AString: string): Integer;
var
  NewString: string;
begin
  //do something with the string and assign the new value to NewString
  Result := Lines.Add(NewString);
end;

Open in new window

0
 
LVL 32

Expert Comment

by:ewangoya
Comment Utility
So instead of using
  RichEdit1.lines.Add(xxx)

you will use
  RichEdit1.Add(xxxxx)
0
 

Author Comment

by:cubic77
Comment Utility
Thanks, but I already implemented exactly the same thing. Until I get the answer to my original question, this solution is acceptable but far from good. Why I don't consider it a GOOD solution? Because I have to remember that I have to use the exception (RichEdit.Add) instead of the normal method.

So, probably in 3-4 months I will accidentally use RichEdit.Lines.Add and I will start to wonder why my RichEdit is not working as expected.
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

Author Comment

by:cubic77
Comment Utility
Actually this solution will became GOOD if the is a way to make the original method (lines.add) not to work anymore. In this case obviously I will see the error message while trying to use it and I will probably remember to use the new method.
0
 
LVL 32

Accepted Solution

by:
ewangoya earned 500 total points
Comment Utility
In that case you will have to encapsulate the TRichEdit in a new control, then expose the public methods of TRichEdit and install that control in your component palette.

Then replace all your TRichEdit controls with the new one.

I can show you how to do that, but right now I'm working on something
0
 

Author Comment

by:cubic77
Comment Utility
> I can show you how to do that, but right now I'm working on something
No. I got it. Thanks.

I also had that idea. What I actually wanted was to see if there is any way to override (for real) the Add method.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

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…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

772 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now