Solved

Formatting a text string for TRichEdit

Posted on 1999-01-01
6
348 Views
Last Modified: 2010-04-04
I need the code that would allow me to change the formatting style of parts of a string programmatically.  The information provided is only displayed to the user.  They cannot change what is entered into the TRichEdit component.  I know how to add a line of text to the TRichEdit component, just not how to format the string before it gets added.  For example:

Defition - This is a description.

where 'Definition' is bolded and the rest of the text is normal.
0
Comment
Question by:tecmaster
6 Comments
 
LVL 2

Expert Comment

by:rene100
ID: 1354168
hi

Simply change the SelAttributes property of the TRichEdit and add the new text with .lines.add('your text').

regards
rene
0
 
LVL 10

Expert Comment

by:ptmcomp
ID: 1354169
Hi tecmaster

You can use the formatting command that you'll see if you open a RTF file with notepad:

\deflang1033\pard\qc\plain\f2\fs32\cf1\b Rich Edit Control Overview
\par \plain\f2\fs16\cf0\b (from Win32SDK Help)
\par \pard\plain\f2\fs20\cf0
\par \pard\li500\ri840\fi-20\plain\f2\fs20\cf0 A rich edit
\par \pard\li480\ri840\plain\f2\fs20\cf0
\par Rich edit controls support almost all of the messages and controls, see \plain\f2\fs20\cf0\i Edit Controls\plain\f2\fs20\cf0 .
\par

To create the command sequences I recommend to use wordpad or sth. like this.

regards ptm
0
 
LVL 10

Expert Comment

by:ptmcomp
ID: 1354170
Sorry I forgot to tell you that you cannot add RTF command by adding a line. You have to create a stream and afterthat you can load the stream in the RTF component.
The answer of rene100 will not do what you want because he adds a hole line. But if you add just some text: RichEdit1.SelText:='Test' it will work.
0
What Security Threats Are You Missing?

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.

 
LVL 3

Expert Comment

by:philipleighs
ID: 1354171
ptmcomp, I don't agree that your way is necessary. Lots of work for nothing. Instead:

Lines.Clear;
SelAttributes.Size := 16;
SetSelTextBuf('Size is 16');
SelAttributes.Color := clRed;
SetSelTextBuf('Size is 16 and color is red');
SelAttributes.Size := 8;
SelAttributes.Name := 'Times New Roman';
SetSelTextBuf('Size is 8, font is Times');

This will appear on one line.
To insert a line break, do this:
SetSelTextBuf('End of Line'#13#10'Start of new line.');

0
 

Author Comment

by:tecmaster
ID: 1354172
rene100, For obvious reasons your answer won't work.

ptmcomp, although your answer most likely would do the job, it seems to me to be pretty complex.

philipleighs, Pefect.  It took me a bit of time to understand how and why this works and it does so exactly as I want, allowing me to do even more than what I anticipated.  Thanks.  Please post your comment as the answer and I will gladly give it an A.

Thanks everyone for your help.

Tecmaster
0
 
LVL 3

Accepted Solution

by:
philipleighs earned 70 total points
ID: 1354173
Answer from above.
Glad to help, Cheers.

>>
ptmcomp, I don't agree that your way is necessary. Lots of work for nothing. Instead:

Lines.Clear;
SelAttributes.Size := 16;
SetSelTextBuf('Size is 16');
SelAttributes.Color := clRed;
SetSelTextBuf('Size is 16 and color is red');
SelAttributes.Size := 8;
SelAttributes.Name := 'Times New Roman';
SetSelTextBuf('Size is 8, font is Times');

This will appear on one line.
To insert a line break, do this:
SetSelTextBuf('End of Line'#13#10'Start of new line.');
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

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…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

759 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

22 Experts available now in Live!

Get 1:1 Help Now