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


Different line colors in a Memo/RichEdit

Posted on 1999-07-26
Medium Priority
Last Modified: 2013-11-22
How do I write with different colors in a Memo/Richedit? I would like to use it in the following way:

 str : string;
  if pos('g', str) then Memo1.Lines.Add( --something green)
  if pos('r', str) then Memo1.Lines.Add( --something red)


Question by:volavy
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

Accepted Solution

Hamilton earned 90 total points
ID: 1391248
I'm afraid I don't exactly understand your code example. But I can provide you a procedure which adds a line to a TRichEdit in a specified color like this:

procedure AddRichLine(Rich: TRichEdit; const s: string; Color: TColor);
  Posit: Integer;
  Posit := Length(Rich.Text);
  Rich.SelStart := Posit;
  Rich.SelLength := Length(s);
  Rich.SelAttributes.Color := Color;
  Rich.SelLength := 0;
  Rich.SelStart := Length(Rich.Text);

If this procedure doesn't do the thing you want, please reject the answer and give me a comment on where you have your difficulties ...


LVL 13

Expert Comment

ID: 1391249
In TRichEdit:

  RichEdit1.SelAttributes.Color := clGreen;
  RichEdit1.Lines.Add('I am green!');
  RichEdit1.SelAttributes.Color := clRed;
  RichEdit1.Lines.Add('I am red!');

Don't think you can use colors in a memo in a proper way.



Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : All lightning effects with instructions : http://www.mediaf…
Suggested Courses

721 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