Lazarus

Programming => Packages and Libraries => RichMemo => Topic started by: p95x on January 05, 2013, 07:21:12 pm

Title: TRichMemo Additional function
Post by: p95x on January 05, 2013, 07:21:12 pm
Hello,

after having successfully installed the RichMemo component (http://wiki.freepascal.org/RichMemo) on Windows 8 64bit,  I wonder why no procedure exists which with you can add formatted text. You can only modify the format of existing text.

That's why I want to recommend this procedure in RichMemo.pas
l.207
Code: [Select]
procedure TCustomRichMemo.AddFormattedString(str: string; fnt: TFontParams);
// fnt can be passed with GetFontParams or manually created
var
  i, j: integer;
begin
  i := Length(Lines.Text) - Lines.Count;// cr as #10#13 is counted only once so subtract it once
  j := Length(str) + 1; // +1 to make the cr the same format
  Lines.Add(str);
  SetTextAttributes(i, j, fnt);  //apply now
end;
and add l.55
Code: [Select]
  public
    procedure AddFormattedString(str: string; fnt: TFontParams);

Maybe you can tell me why this is not yet included?

Edit: extension:
Code: [Select]
// ####
// fnt can be passed with GetFontParams or manually created
// wordwrap=false !
procedure TCustomRichMemo.AddFormattedString(str: string; fnt: TFontParams);
var
  i, j: integer;
begin
  i := Length(Lines.Text) - Lines.Count; //start
  j := Length(str) + 1;                  //length (+1: to make CR also "fnt")
  Lines.Add(str);                        //just add the string
  SetTextAttributes(i, j, fnt);          //apply formatting
end;

// adding two strings with each different style
procedure TCustomRichMemo.AddFormattedString2(str1, str2: string;
  fnt1, fnt2: TFontParams);
var
  i, j, k: integer;
begin
  i := Length(Lines.Text) - Lines.Count;
  j := Length(str1);
  k := Length(str2) + 1;
  Lines.Add(str1 + str2);
  SetTextAttributes(i, j, fnt1);
  SetTextAttributes(i + j, k, fnt2);
end;

Regards :)
TinyPortal © 2005-2018