Solved

Richedit - formatting

Posted on 2002-05-02
11
421 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
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 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

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…
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…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

717 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