Solved

Formatting a text string for TRichEdit

Posted on 1999-01-01
6
382 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
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 
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

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

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
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
Course of the Month7 days, 6 hours left to enroll

623 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