Solved

Formatting a text string for TRichEdit

Posted on 1999-01-01
6
367 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 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Delphi selector screen 2 92
Press three keys together and trigger a function 3 67
Installshield for Embarcadero EX 10.1 Berlin 4 74
Tvertscrollbox like a whatsapp layout 5 53
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

733 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