Solved

Text in a Tmemo to appear in different colors.

Posted on 2007-04-05
3
314 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 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

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. …
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.
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 keystrokes in Netbeans IDE 8.0 for Windows.

786 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