WPCubed Product Support

easy to use procedure for adding Text

Hi @all!

I want to add some simple reports to my application. For this I want to write a procedure to add text with some attributes. This is my code:

procedure TmDLMain.AddText
                  ParNumber: Integer;       // Paragraph number
                  NewPage: Boolean;         // Insert new Page bevor text add
                  FontName: String;         // Font for text
                  FontSize: Integer;        // Size for text
                  Color: TColor;            // Color of the text
                  Text: String              // Text to Add ...
                  );
begin
    if NewPage = True then RichText.InputString(#12);  // New Page
    RichText.CPParNr := ParNumber;
    RichText.ActiveParagraph.ClearText;
    RichText.WritingAttr.SetColor(Color);
    RichText.WritingAttr.SetFontName(FontName);
    RichText.WritingAttr.SetFontSize(FontSize);
    RichText.InputString(Text);
end;

Is this the correct way to add text or is there a better solution?

#1 ♥ 0
4.5k Views 2 users read 2 min
support

Hi,

Looks fine - except for

RichText.CPParNr := ParNumber;

that does not make sense to me. If you add at current position you don't need that part.

Julian

#2 ♥ 0

Hi !

I treid this:

procedure TmDLMain.AddText( 
                  ParNumber: Integer;       // Paragraph number
                  NewPage: Boolean;         // Insert new Page bevor text add
                  FontName: String;         // Font for text
                  FontSize: Integer;        // Size for text
                  Color: TColor;            // Color of the text
                  Text: String              // Text to Add ...
                  );
begin
    if NewPage = True then RichText.InputString(#12);  // New Page
    RichText.ActiveParagraph.ClearText;
    RichText.WritingAttr.SetColor(Color);
    RichText.WritingAttr.SetFontName(FontName);
    RichText.WritingAttr.SetFontSize(FontSize);
    RichText.InputString(Text);
end;

procedure TmDLMain.TBXItem2Click(Sender: TObject);
begin
  RichText.Clear;
  AddText(0, False, 'Courier New', 9, clGreen, '123456789012345678901234567890');
  AddText(1, False, 'Courier New', 9, clRed, 'HalloWelt"!');
end;

The result is online 'HalloWelt"! . I can´t see 1234567........

Is there something missing to begin a new paragraph?!

#3 ♥ 0
support

InputString(#13) is missing for a new par (insetad of #12)

#4 ♥ 0

Hi !

Ok, #13 works fine now.

But how can I set styles like bold, italic, etc?
Is this the procedire WritingAttr.SetStyle ?

#5 ♥ 0
This category is archived. No new posts are possible.