Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How do I override TRichEdit.Lines.Add ?

Posted on 2011-02-10
6
Medium Priority
?
414 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
[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
  • 3
  • 3
6 Comments
 
LVL 32

Expert Comment

by:Ephraim Wangoya
ID: 34864597

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:Ephraim Wangoya
ID: 34864613
So instead of using
  RichEdit1.lines.Add(xxx)

you will use
  RichEdit1.Add(xxxxx)
0
 

Author Comment

by:cubic77
ID: 34864789
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:cubic77
ID: 34864822
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:
Ephraim Wangoya earned 2000 total points
ID: 34864849
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
ID: 34864914
> 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

715 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