?
Solved

Text in a Tmemo to appear in different colors.

Posted on 2007-04-05
3
Medium Priority
?
319 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 2000 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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand column That will then direct you to their download page. From that p…
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

771 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