?
Solved

Text Formatting

Posted on 2002-03-08
18
Medium Priority
?
265 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 400 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

Technology Partners: 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!

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

719 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