Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

RichEdit Run-Time Formatting?

Posted on 2002-07-22
7
Medium Priority
?
1,061 Views
Last Modified: 2013-11-22
I have a RichEdit component, and would like to set the default Tab spacing to 4 spaces... how do I do that?  And then, how would I instruct the program to insert a tab?

Then, I just need to know how to format data "on the fly".

Imagine the following "tagged" line :

[fsNormal]word01[tab]word02[fsBold]word03
[newline]
[fsNormal]word04[tab][color=red]word05[fsBold]word06

... hopfully, you can understand what i'm trying to say here. ;-)

You see, the following :

With RickEdit1 do begin
  Lines.Add('word01 word02 word03 etc. etc.');
end;

.. is all well and good, but, I need to insert tabs, and set color and font weight properties on the fly, for certain words.

Whenever I try to do this, with the Font.Style := [fsBold] thing, it sets the global property of the RichEdit component.

Can anyone here advise me?
0
Comment
Question by:nicey
  • 3
  • 2
  • 2
7 Comments
 
LVL 14

Expert Comment

by:DragonSlayer
ID: 7170877
You can do something like this:

with RichEdit1 do
begin
  Lines.Add('word01 word02 word03');
  SelStart := 0;
  SelLength := 6;
  SelAttributes.Style := [fsBold];
  SelStart := 7;
  SelLength := 6;
  SelAttributes.Color := clRed;
  SelStart := 14;
  SelLength := 6;
  SelAttributes.Style := [fsUnderline];
  SelAttributes.Color := clBlue;
end;



HTH
DragonSlayer.
0
 
LVL 35

Accepted Solution

by:
Slick812 earned 225 total points
ID: 7170921
hello nicey, you set the Selection of the Rich Edit and then adjust the selection properties to chsnge the Text that's selected. About the Tab stops, You can set a Paragraphs Tap stops with the Rich Edits Paragraph Properties, But It seems that the tab stops, ar used only in that paragraph, which in a TRichEdit defaults to just One Line, so you will need to set the Tabs for every line you want your Tab in. Also you say you want a Tab stop 4 spaces wide, but with which Font width? ?, the Tab stops are in Pixel widths. And to add tab stops use the #9 charater


procedure TForm1.button_NewTextClick(Sender: TObject);
begin
RichEdit1.Clear;
{there are 3 tab stops in this line}
RichEdit1.Lines.Add('word01'#9'word02'#9'word03'#9'word04 word05');
RichEdit1.SelStart := 7;
RichEdit1.SelLength := 6;
{where ever the Selection is, seems to be the Paragraph
(line) for the paragraph properties to be set}
RichEdit1.SelAttributes.Color := clAqua;
RichEdit1.SelAttributes.Name := 'Comic Sans MS';
RichEdit1.SelAttributes.Size := 16;
RichEdit1.SelAttributes.Style := [fsBold];
{the Richedit Paragraph seems to default to only one line
so you may need to set the Tabs for each line you use tabs in}
RichEdit1.Paragraph.Tab[0] := 60;
RichEdit1.Paragraph.Tab[1] := 60;
RichEdit1.Paragraph.Tab[2] := 60;
{these Tabs are for this single line}
RichEdit1.SelStart := 14;
RichEdit1.SelLength := 6;
RichEdit1.SelAttributes.Color := $0090FD;
RichEdit1.SelAttributes.Name := 'Times New Roman';
RichEdit1.SelAttributes.Size := 13;
RichEdit1.SelStart := 0;
RichEdit1.SelLength := 0;
end;


- - - - - - - - - - - -  - - - - - - -

you could use Canvas.TextWidth for the tabs

Canvas.Font := TheFontYouNeed;
RichEdit1.Paragraph.Tab[0] := Canvas.TextWidth('    ');
0
 
LVL 1

Author Comment

by:nicey
ID: 7172392
Ok, this is excellent.  Thank you both.

After I posted this question, I went back and played abit more (I don't think the documentation for RichEdit is all that great), and managed to come up with a FUNCTION, whereby I can pass parameters to, and then the text, I can then use that function call inside the Lines.Add(), but i'm falling over with selecting text.

How is the select text defined?  Is it from the top left, to the bottom right, in pixels or characters?

Or, is it line by line, from the first character, to the last character of that line... or, in pixels, line by line?

Once cleared up, I should have all I need to go about dancing with RichEdit.

Your input has been most informative so far.  Cheers.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 35

Expert Comment

by:Slick812
ID: 7172697
OK, with these

RichEdit1.SelStart := 7;
RichEdit1.SelLength := 6;

the values are in Charaters I.E.

RichEdit1.SelStart := 7;  
is 8 char from the begining of the text buffer for the Richedit, 0 being the First Charater

I believe all of this in in the Delphi Help for TRichedit--Properties--SelStart

and for

RichEdit1.SelLength := 6;
this is SIX charaters in Length
0
 
LVL 14

Expert Comment

by:DragonSlayer
ID: 7173263
Cheers :)
0
 
LVL 1

Author Comment

by:nicey
ID: 7175057
I don't think I could give the points to just one person here... is there a way I can split the points, or somthing like that?
0
 
LVL 35

Expert Comment

by:Slick812
ID: 7175492
you can award these points to one and then post another "Fake" question something like

Question -
"Points for Whoever"
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

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 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…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

564 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