Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Text in a Tmemo to appear in different colors.

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deleti…
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 NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

564 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