Solved

RichEdit font problem

Posted on 2002-04-28
3
719 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

746 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