Solved

Richedit - formatting

Posted on 2002-05-02
11
396 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
  • 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

920 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now