I need to do bold some words when i am doing a rtf file

I'm not american. So i dont speak english language; apologize and now I'm doing a system where the user wants to make a rtf file. That file contains a list of customers like this one:

AVALOS AGUILAR MA. GUADALUPE
  Gertrudis Sánchez # 340-A
  Lázaro Cárdenas 60630
  Tels: ........................................534-7117

AYALA MENDEZ VICTOR MANUEL
  Fco. J. Mújica Pte. # 27 int. 2
  Centro 60600
  Tels: ........................................534-4522
  Cel. .......................... 044 (453)100-6475

BARAJAS PEREZ JOSEFINA
  Manuel de Alderete y Soria Nte. # 223
  Benito Juárez 60650

But he wants the first line bold and the first records everything is good but when there is four or more records all the lines are bold. My code is this:
   RTF.Lines.Add((Fields[1].AsString)); //nombre
    if CBNegrita.Checked then//poner en negrita el nomnbre
      begin
      RTF.SelStart:=VarSelStart;
      RTF.SelLength:=Length(Fields[1].AsString);
      VarSelStart:=VarSelStart+Length(Fields[1].AsString)+1;
      RTF.SelAttributes.Style:=RTF.SelAttributes.Style + [fsBold]
      end;

I 'm using a TRichEdit to make it bold and i'm  using the variable "VarSelStart" to count every character when i add a new line by this way:
   if Fields[12].AsString<>'' then
      begin
      RTF.Lines.Add('  '+(Fields[12].AsString));//correo
      VarSelStart:=VarSelStart+1+Length('  '+(Fields[12].AsString));
      end;
 what is wrong?
Thanks
 
NefyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

developmentguruPresidentCommented:
After turning on the bold the style remains.  Add the next section, mark it, and turn the bold off again.  
0
NefyAuthor Commented:
Thanks but i do this thing with two tables enterprises and people. When i do it with enterprises works. but with people doesn't. And i did your suggestion and doesn't changes. now my code is:

    begin
    RTF.Lines.Add((Fields[1].AsString)); //nombre
    RTF.SelAttributes.Style:=RTF.SelAttributes.Style - [fsBold];
    if CBNegrita.Checked then//poner en negrita el nomnbre
      begin
      RTF.SelStart:=VarSelStart;
      RTF.SelLength:=Length(Fields[1].AsString);
      VarSelStart:=VarSelStart+Length(Fields[1].AsString)+1;
      RTF.SelAttributes.Style:=RTF.SelAttributes.Style + [fsBold];
      end;

and just the first 5 or 6 records are fine
0
developmentguruPresidentCommented:
Place a TRichEdit on a form with a button, paste in the following code and attach the buttons on click event.  This code adds each line as bold or not.  Let me know if you need more.
unit Unit2;
 
interface
 
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ComCtrls, RichEdit;
 
type
  TForm2 = class(TForm)
    RichEdit1: TRichEdit;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
    procedure AddLine(Line : string; Bold : boolean);
  public
    { Public declarations }
  end;
 
var
  Form2: TForm2;
 
implementation
 
{$R *.dfm}
 
procedure TForm2.AddLine(Line: string; Bold: boolean);
begin
  with RichEdit1 do
    begin
      Lines.Add(Line);
      SelStart := Length(Lines.Text) - Length(Line) - 2;
      SelLength := Length(Line);
      if Bold then
        SelAttributes.Style := SelAttributes.Style + [fsBold]
      else
        SelAttributes.Style := SelAttributes.Style - [fsBold];
    end;
end;
 
procedure TForm2.Button1Click(Sender: TObject);
begin
  with RichEdit1 do
    begin
      Lines.Clear;
 
      AddLine('Bold', true);
      AddLine('Normal', false);
      AddLine('Bold', true);
      AddLine('Normal', false);
      AddLine('Bold', true);
      AddLine('Normal', false);
      AddLine('Bold', true);
      AddLine('Normal', false);
    end;
end;
 
end.

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
NefyAuthor Commented:
I did it like you write it, and now the first 10 lines are fine. But also i discovered that other trouble was that my richedit was small so now is more big and everything works but when it is small don't works when the line is big.

Thanks a lot
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.