Solved

Text Formatting

Posted on 2002-03-08
18
252 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
 
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

707 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now