Solved

Richedit - formatting

Posted on 2002-05-02
11
392 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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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…
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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

744 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

11 Experts available now in Live!

Get 1:1 Help Now