Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Formatting a text string for TRichEdit

Posted on 1999-01-01
6
Medium Priority
?
391 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
[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
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
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!

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

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.

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…
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…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

670 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