Solved

Text in a Tmemo to appear in different colors.

Posted on 2007-04-05
3
317 Views
Last Modified: 2013-11-23
Hi Experts,
I have a TMemo called 'txtLicense' which is populated as follows:

// populate license info panel
        txtLicense.Text :=
          'LICENSE INFO:' + #13#10 + #13#10 +
          '32/4                      = ' +
          BoolToStr((RTU.license AND _mask_32_4) <> 0, TRUE) + #13#10 +
          'TL1                       = ' +
          BoolToStr((RTU.license AND _mask_TL1) <> 0, TRUE) + #13#10 +
          'SNMP                   = ' +
          BoolToStr((RTU.license AND _mask_SNMP) <> 0, TRUE) + #13#10 +
          'TBOS                    = ' +
          BoolToStr((RTU.license AND _mask_TBOS) <> 0, TRUE) + #13#10 +
          'TABS                    = ' +
          BoolToStr((RTU.license AND _mask_TABS) <> 0, TRUE) + #13#10 +
          'MODEM                = ' +
          BoolToStr((RTU.license AND _mask_MODEM) <> 0, TRUE) + #13#10 +
          'ETHERNET          = ' +
          BoolToStr((RTU.license AND _mask_ETHERNET) <> 0, TRUE) + #13#10 +
          'MPBM                   = ' +
          BoolToStr((RTU.license AND _mask_MPBM) <> 0, TRUE) + #13#10 +
          'ANALOG TYPE 2  = ' +
          BoolToStr((RTU.license AND _mask_ANALOG_TYPE2) <> 0, TRUE) + #13#10 +
          'WEBSERVER       = ' +
          BoolToStr((RTU.license AND _mask_WEBSERVER) <> 0, TRUE) + #13#10 +
          'OEM                     = ' +
          BoolToStr((RTU.license AND _mask_OEM) <> 0, TRUE);

As a result the text in the Tmemo appears is as follows:
LICENSE INFO:

32/4                      = True
TL1                       = True
SNMP                   = True
TBOS                    = True
TABS                    = True
MODEM                = True
ETHERNET          = True
MPBM                   = True
ANALOG TYPE 2  = True
WEBSERVER       = True
OEM                     = False

How do I make the word 'False' appear in color red? Or better yet the entire line where it is false.
Thanks.



0
Comment
Question by:QurbanDurrani
[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
3 Comments
 
LVL 28

Accepted Solution

by:
2266180 earned 500 total points
ID: 18862665
it is a little harder to use a memo for that. instead, use a trichedit. something like:

var i:integer;
begin
  richedit1.Lines.clear;
  richedit1.Lines.Add('LICENSE INFO:');
  richedit1.Lines.Add('');

  i:=richedit1.GetTextLen;
  richedit1.Lines.Add( '32/4                      = ' +
          BoolToStr((RTU.license AND _mask_32_4) <> 0, TRUE) );
  richedit1.SelStart:=i;
  richedit1.SelLength:=richedit1.GetTextLen-i-2;
  if (RTU.license AND _mask_32_4) = 0 then
    richedit1.SelAttributes.Color:=clred;

  i:=richedit1.GetTextLen;
  richedit1.Lines.Add('TL1                       = ' +
          BoolToStr((RTU.license AND _mask_TL1) <> 0, TRUE) );
  richedit1.SelStart:=i;
  richedit1.SelLength:=richedit1.GetTextLen-i-2;
  if (RTU.license AND _mask_TL1) = 0 then
    richedit1.SelAttributes.Color:=clred;

  etc.

  richedit1.SelLength:=0;
  richedit1.SelStart:=richedit1.GetTextLen;
end;

you can make a small procedure for adding the lines so that you don't copy paste too much
0
 

Author Comment

by:QurbanDurrani
ID: 18873867
Ciuly,
Thanks alot. Your comment was excelent in solving my problem from begining to end. Just for my understanding, in the line  'richedit1.SelLength:=richedit1.GetTextLen-i-2;', what is the purpose behind
'-2'.
Thanks again.  
0
 
LVL 28

Expert Comment

by:2266180
ID: 18874384
when you add a line, it will add a #13 and a #10 characters at the end of teh text as well. you don't need those selected ;)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
maven project import to eclipse problems 13 122
Object Data Source 4 138
Eclipse versons - run configurations 2 86
VB.Net Reusable Form Layout 4 175
In our object-oriented world the class is a minimal unit, a brick for constructing our applications. It is an abstraction and we know well how to use it. In well-designed software we are not usually interested in knowing how objects look in memory. …
Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

733 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