Solved

Text in a Tmemo to appear in different colors.

Posted on 2007-04-05
3
312 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:
ciuly 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:ciuly
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

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…
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org (http://seleniumhq.org) Go to that link and select download selenium in the right hand columnThat will then direct you to their downlo…
The viewer will learn how to use and create keystrokes 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.

705 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now