Solved

Formatting a text string for TRichEdit

Posted on 1999-01-01
6
355 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

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…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

785 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