• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 270
  • Last Modified:

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
 
0
Nefy
Asked:
Nefy
  • 2
  • 2
1 Solution
 
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
 
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

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now