• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1027
  • 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 GOracle 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
 
Emmanuel PASQUIERFreelance Project ManagerCommented:
or you custom draw your memo, but that is going to be more difficult than using TRichEdit
0
 
Emmanuel PASQUIERFreelance Project ManagerCommented:
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
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
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
 
Emmanuel PASQUIERFreelance Project ManagerCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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