Solved

RichEdit font problem

Posted on 2002-04-28
3
721 Views
Last Modified: 2013-12-03
Hi guys,

This is my problem... I have few procedures to change the font in a richedit component

procedure WriteA(s : string);
begin
  Form1.RichEdit1.Font.Name := 'Chess Merida';
  Form1.RichEdit1.Font.Size := 20;
  Form1.RichEdit1.Lines.Add(s);
end;

procedure WriteB(s: string);
begin
  Form1.RichEdit1.Font.Name := 'Courier New';
  Form1.RichEdit1.Font.Size := 10;
  Form1.RichEdit1.Lines.Add(s);
end;

and I use both procedures alternate over a richedit... i.e.

   WriteA('Hello');
   WriteB('GoodBye');

but... when I finish writing over the richtext,  the font assigned to each string is not respected. I mean, everything appears with the same font... Am I missing something?

best regards,
Manuel Lopez (lopem)
0
Comment
Question by:lopem
  • 2
3 Comments
 
LVL 17

Accepted Solution

by:
inthe earned 50 total points
ID: 6975367
hi,
you need to change teh selattributes of it ,heres an example from my paq:

procedure TForm1.Button2Click(Sender: TObject);
var
Start,fin,SelStart,Selfin,
online : integer;
Begin
With RichEdit1 do
Begin
Lines.BeginUpdate;
Perform(EM_GETSEL,LongInt(@Start),LongInt(@fin));
online:=Perform(EM_LINEFROMCHAR,SelStart,0);
SelStart:= Perform(EM_LINEINDEX,online,0);
Selfin := SelStart+Length(Lines[online]);
Perform(EM_SETSEL,SelStart,Selfin );
Selattributes.color := clblue;
Selattributes.Name := 'Courier New';
Perform(EM_SETSEL, Start,fin );
lines.add('hello');
Lines.EndUpdate;
Setfocus;
end;
end;

procedure TForm1.Button3Click(Sender: TObject);
var
Start,fin,SelStart,Selfin,
online : integer;
Begin
With RichEdit1 do
Begin
Lines.BeginUpdate;
Perform(EM_GETSEL,LongInt(@Start),LongInt(@fin));
online:=Perform(EM_LINEFROMCHAR,SelStart,0);
SelStart:= Perform(EM_LINEINDEX,online,0);
Selfin := SelStart+Length(Lines[online]);
Perform(EM_SETSEL,SelStart,Selfin );
Selattributes.color := clred;
Selattributes.size := 12;
Perform(EM_SETSEL, Start,fin );
Selattributes.Name := 'Arial';
lines.add('hello in red');
Lines.EndUpdate;
Setfocus;
end;
end;
0
 
LVL 3

Author Comment

by:lopem
ID: 6975377
Wow, InThe...

Thanks for the fast response... I just changed:

procedure WriteA(s : string);
begin
  Form1.RichEdit1.SelAttributes.Name := 'Chess Merida';
  Form1.RichEdit1.SelAttributes.Size := 20;
  Form1.RichEdit1.Lines.Add(s);
end;

procedure WriteB(s: string);
begin
  Form1.RichEdit1.SelAttributes.Name := 'Courier New';
  Form1.RichEdit1.SelAttributes.Size := 10;
  Form1.RichEdit1.Lines.Add(s);
end;

And everything worked now! Thanks a lot!

best regards,
Manuel Lopez (lopem)
0
 
LVL 17

Expert Comment

by:inthe
ID: 6975418
yep that'll work fine :)

also just note to say the example was from using trichedit98 (from torrys)
using trichedit98 you can change the background color of each line using selattributes.backcolor which normal richedit dont have.
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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

911 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

17 Experts available now in Live!

Get 1:1 Help Now