Solved

Text Formatting

Posted on 2002-03-08
18
262 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses
Course of the Month11 days, 4 hours left to enroll

628 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