Solved

ANSI Color and TRichEdit

Posted on 2000-03-10
4
431 Views
Last Modified: 2010-04-04

I'm trying to use a RichEdit box to create a custom terminal emulation
program that supports ANSI color codes (no other ANSI Escape codes are
needed currently), however, I've run into a slight problem with the
RichEdit control.  If I try to set the text on the control via
RichEdit1.Text := RichEdit1.Text + 'Blah blah'; or
RichEdit1.Lines.Text := RichEdit1.Lines.Text + 'Blah blah'; it strips
all my color and style changes.  However, if I use
RichEdit1.Lines.Add() or RichEdit1.Lines.Append(), it automatically
inserts a line break, which I don't want.

So far, any simple processes I've thought of to eliminate this haven't
worked.  I store the raw text with ANSI codes in a separate text file
and reparse the entire RichEdit control with an array of positions and
style/color definitions, but that would be extremely slow once I have
1000 lines or so.

Is there any simpler way to do this?  Or perhaps any alternate
components I could use which would parse this for me automatically?
0
Comment
Question by:DirewolfX
  • 2
4 Comments
 
LVL 5

Expert Comment

by:TheNeil
ID: 2604300
You could try this:

iStart := RichEdit1.Text.Length;
RichEdit1.Text.Add('Blah, blah, blah');
RichEdit1.SelStart := iStart;
RichEdit1.SelLength := Length(RichEdit1.Text) - iStart;
RichEdit1.SelAttributes.Font.Color := clRed;

This will set the text attributes for each bit of text as you add it. If you want to speed things up then only use the above code when you need to change the text style/colour

The Neil
0
 
LVL 27

Accepted Solution

by:
kretzschmar earned 50 total points
ID: 2604313
just use
the seltext-property for inserting text like

richedit1.seltext := 'Blah Blah Blah';
0
 

Author Comment

by:DirewolfX
ID: 2606571
Kretzchmar's solution was correct.  Thanks!
0
 

Author Comment

by:DirewolfX
ID: 2606573
The solution worked, but it wasn't well explained.

However, if anyone knows any good third party ANSI text controls, I'm still interested...
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

708 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

17 Experts available now in Live!

Get 1:1 Help Now