Solved

ANSI Color and TRichEdit

Posted on 2000-03-10
4
433 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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

810 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