Solved

Text Formatting

Posted on 2002-03-08
18
256 Views
Last Modified: 2013-11-22
Assuming I have a TMemo Control on a form how could i highlite (i.e. make bold) every instance of a word.  Kind of like a very cheap and easy syntax highlighting thingamy.  

Many Thanks In Advance.

James
0
Comment
Question by:phuzzy
  • 9
  • 4
  • 2
  • +2
18 Comments
 
LVL 9

Expert Comment

by:ginsonic
ID: 6850499
You wish to bold a specified word into memo lines ?
0
 
LVL 17

Expert Comment

by:Wim ten Brink
ID: 6850558
Use a TRichEdit control, not a TMemo control A TMemo control doesn't support any highlighting, only selecting of part of the text between two positions.
0
 
LVL 3

Expert Comment

by:cubud
ID: 6850614
Use richedit
then use SelStart, SelLength and SelAttributes properties.

Look at the richedit demo in the DEMOS directory.
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

 
LVL 2

Expert Comment

by:classmate
ID: 6850658
Solution 1:
Use capitals for highlighting

Solution 2:
Use a TRichEdit instead.


In either way you can use the StringReplace function to do what you want, but with TRichEdit controls it's a bit more complicated. Have to use the Lines.SaveToStream/LoadFromStream methods and make a string point to the data you want to change. Next, you need to know RichEdit formatting.

Classmate.
0
 
LVL 9

Accepted Solution

by:
ginsonic earned 100 total points
ID: 6850696
You can use ColorMemo from http://www.torry.net/memos.htm .
Is freeware , but no source codes .
0
 
LVL 9

Expert Comment

by:ginsonic
ID: 6850711
Same address for ESColorMemo v.1.0 . Freeware with source code . Tested and work perfect .
0
 
LVL 9

Expert Comment

by:ginsonic
ID: 6850740
And many anothers alike freware memos (TGSMemo & TGSMemoHTMLCode v.1.0 ..etc)
0
 
LVL 2

Expert Comment

by:classmate
ID: 6850761
Solution 1:

Memo.Text :=
  StringReplace (
    Memo.text, 'myword', 'MYWORD',
    [rfReplaceAll, rfIgnoreCase]
  );


Solution 2:

procedure TForm1.ButtonHighLightClick(Sender: TObject);
const
  boldon = '\b ';
  boldoff = '\b0 ';
var
  Replacement : string;
  RStream : TMemoryStream;
begin
  RStream := TMemoryStream.Create;
  Richedit1.Lines.SaveToStream(RStream);

  SetLength (Replacement, RStream.size);
  StrCopy (PChar(Replacement), RStream.memory);

  replacement := StringReplace (replacement, 'myword', boldon + 'myword' + boldoff, [rfReplaceAll, rfIgnoreCase]);

  RStream.Size := Length(Replacement);
  StrCopy (RStream.Memory, PChar(Replacement));

  RStream.Seek(0, soFromBeginning);
  RichEdit1.Lines.LoadFromStream(RStream);

  RStream.Free;
end;


classmate.
0
 
LVL 9

Expert Comment

by:ginsonic
ID: 6850825
Whay to use RichEdit when the question is about TMemo ?
And is possible to do that with Memo . I just tested couple ( freware with source code ) components from Torry .
0
 
LVL 2

Expert Comment

by:classmate
ID: 6850913
Out of curiousity, do theese components have one simple method of highligthing the desired words?

0
 
LVL 2

Expert Comment

by:classmate
ID: 6850917
(this freeware code, i meant :-) )
0
 
LVL 3

Expert Comment

by:cubud
ID: 6850924
My favourite component is SynEdit

http://sourceforge.net/projects/synedit/

You can specify you own rules for highlighting, and it comes with some pre-defined rules (Pasca, Java, etc).

http://www.HowToDoThings.com
0
 
LVL 9

Expert Comment

by:ginsonic
ID: 6851051
In ESColorMemo v.1.0 you can choice how many words you wish and assign for each own color .
Have a problem . If select couple words and then deselect, the text is paint with default color . But this is very easy to fix . Just add a new Refresh message into component .
0
 
LVL 9

Expert Comment

by:ginsonic
ID: 6851058
Else wait 2-3 weeks to release my transparent/own transparence memo :) Will have this features , too .
0
 

Author Comment

by:phuzzy
ID: 6853495
hello everyone... sorry about the time delay....

ginsonic : how do you use that ESColorMemo control... i dont understand the TcolorItem/s stuff... any chance you could supply me with a sample section of code????

Cant find any documentation on it either.  But it seems very good.
0
 
LVL 9

Expert Comment

by:ginsonic
ID: 6853504
What kind of code ? Can be more specified ?
0
 

Author Comment

by:phuzzy
ID: 6853519
no in fact it's not important any more i figured out how it wrks but it's not brilliant... but it will do.

Thanks

James
0
 
LVL 9

Expert Comment

by:ginsonic
ID: 6854174
See you ... on net :)
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

828 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