Solved

ANSI Color and TRichEdit

Posted on 2000-03-10
4
438 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
[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
  • 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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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 video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

729 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