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
Solved

ANSI Color and TRichEdit

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

840 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