• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 963
  • Last Modified:

change font of memo on particular words

Hi,

When ON CHANGE...

I want it to if the Tmemo1 finds any of the following charcaters, show themin RED insie the memo. Do not show everything red, just the characters.

Here is the code that works but i need someone toadd the color part to it.
if LastDelimiter('SsUu5$&%.$£nNoOAalIiL`;_?iI', Memo1.text) <> 0 then
          begin
            Windows.MessageBox(handle, 'An incorrect subscription was found. No subscriptions have been added!',  'Invalid subscription found!',
            MB_SYSTEMMODAL or MB_SETFOREGROUND or MB_TOPMOST or MB_ICONHAND) ;
          end

Open in new window

0
boycoder
Asked:
boycoder
1 Solution
 
Geert GruwezOracle dbaCommented:
not possible for a TMemo.

You have to use a TRichEdit

Select the text you want with SelStart and SelLength
and the use the SelAttributes to change the font and color
0
 
epasquierCommented:
or you custom draw your memo, but that is going to be more difficult than using TRichEdit
0
 
epasquierCommented:
Here is the procedure that marks in red all characters of a richedit in a set
procedure MarkInvalidChars(Memo:TRichEdit;Chars:String);
var
 l,i:integer;
 CharSet:Set of Char;
 MText:String;
 SelPosOffset:Integer;
begin
 Memo.SelectAll;
 Memo.SelAttributes.Color:=clBlack;
 CharSet:=[];
 for i := 1 to Length(Chars) do CharSet:=CharSet+[Chars[i]];
 SelPosOffset:=0;
 for l := 0 to Memo.Lines.Count-1 do
  begin
   MText:=Memo.Lines[l];
   for i := 1 to Length(MText) do if MText[i] IN CharSet then
    begin
     Memo.SelStart:=SelPosOffset+i-1;
     Memo.SelLength:=1;
     Memo.SelAttributes.Color:=clRed;
    end;
   SelPosOffset:=SelPosOffset+Length(MText)+1;
  end;
 Memo.SelStart:=0;
end;

Open in new window

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
Ephraim WangoyaCommented:

Forget about the TMemo, that is only used for plain text.
Use TRichEdit instead as suggested above
0
 
boycoderAuthor Commented:
A+ and thanks to both of you for your inputs.
0
 
epasquierCommented:
You know that you can accept multiple answers and split/distribute points proportionally to your estimated value of the answers (by default the website will distribute evenly on multiple selected answers) ?

I say that only because you thank both of us. That's Geert idea, yes, but I took the time to actually write the code.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now