Solved

Richedit - formatting

Posted on 2002-05-02
11
413 Views
Last Modified: 2013-11-22
Hi there!
Problem: I want to format parts of the strings while adding them to the Richedit. Currently:

procedure TForm1.Button1Click(Sender: TObject);
var tst,tend:integer;
begin
 with RichEdit1,Richedit1.SelAttributes do begin

  TSt:=Length(Text);
  Text:=Text+'Blue simple ';
  TEnd:=Length(Text);
  SelStart:=TSt;
  SelLength:=TEnd-TSt;
  Size:=8;
  Color:=clBlue;
  Style:=[];


  TSt:=Length(Text);
  Text:=Text+'Green Italic ';
  TEnd:=Length(Text);
  SelStart:=TSt;
  SelLength:=TEnd-TSt;
  Size:=8;
  Color:=clGreen;
  Style:=[fsItalic];
 end;
end;

it works fine - once :)
When I click Button1 again, I have previous "Green Italic" formatted as blue simple; the last Green Italic appears correctly.

What I'm trying to do is to have as simple as possible way how to change text attributes within the line, preferrably before adding it to RichEdit.

Thanks in advance, this should be simple, but 123 points anyway :)

W_Fox
0
Comment
Question by:W_Fox
[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
  • 2
  • 2
  • +1
11 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6986904
no way,
exceptyou write the string wiht the rtf-tokens and stream (no add) this into the richedit with the win api em_streamin and usage of the editstream structure

sorry no easy way to color a string before adding it into a richedit

meikl ;-)
0
 

Author Comment

by:W_Fox
ID: 6986916
OK, what about changing after adding? Beginupdate and EndUpdate (IIRC) should help avoid flickering...

W_Fox
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6986959
yes,
additional you can with the message em_hideselection toggle the selection-showing on/off
0
Independent Software Vendors: 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 27

Expert Comment

by:kretzschmar
ID: 6986978
there may also a workaround
using a second hidden richedit and
preformat there the line and then
copy/paste the line via cliboard
into the first richedit

just a workaround

meikl ;-)
0
 
LVL 8

Accepted Solution

by:
Cesario earned 123 total points
ID: 6986988
This is what you need

procedure TForm1.Button1Click(Sender: TObject);
begin
  with RichEdit1,Richedit1.SelAttributes do
  begin
   SelStart := GetTextLen;
   Size     :=8;
   Color    :=clBlue;
   Style    :=[];
   selText  := 'Blue simple ';

   SelStart := GetTextLen;
   Size     :=8;
   Color    :=clgreen;
   Style    :=[fsItalic];
   selText  := 'Green Italic ';
  end;
end;
0
 
LVL 6

Expert Comment

by:DrDelphi
ID: 6986995
Kudos Cesario!!

0
 
LVL 8

Expert Comment

by:Cesario
ID: 6986999
Meikl, its possible ;-)

Best Regards

Cesario
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6987179
well, you wrote your string in parts,
didn't know, if this solves the question?

>how to change text attributes within the
>line, preferrably before adding it to RichEdit.

meikl ;-)
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6987189
didn't know, if this solves the question?
could be :-)
0
 

Author Comment

by:W_Fox
ID: 6988051
That's exactly what I need, thanks, Cesario!
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6988164
well, seems i have misread the question :-(

good work, cesario :-)
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Dynamically Created Query 3 70
can i put an image from resource into image tag ? 6 32
DBCtrlGrid, Delphi, Scroll 8 60
Broadcast a message using ICS 2 28
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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

730 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