0

I am trying to implement numbering in TRichEdit component, Delphi. Ideally I want to get the same behavior as in these 3rd party component: enter image description here

As you can see Numbering button works similar way as Bullet button. I mean it sets FirstIdent or LeftIdent (I am not sure) and put the numbers 1,2,3,... instead of bullets. When you move cursor to the left close to number it does not allow to move onto number but jumps one line up.

This is what I got so far:

procedure TMainForm.NumberingButtonClick(Sender: TObject);
var
  i: Integer;
  s: String;
begin
  if NumberingButton.Down then
  begin
    Editor.Paragraph.Numbering := nsNone;
    i := Editor.ActiveLineNo;
    s := Editor.Lines[i];
    insert(inttostr(i)+'. ', s, 1);
    //Editor.Paragraph.LeftIndent := 10;
    Editor.Paragraph.FirstIndent := 10;
    Editor.Lines[i] := s;
  end;
end;

But it does not work as I want. Anybody have any ideas?

pyfyc
  • 127
  • 2
  • 9
  • 1
    Delphi `TRichEdit` does not have native support for this. You are going to need to use a [`PARAFORMAT2`](https://learn.microsoft.com/en-us/windows/win32/api/richedit/ns-richedit-paraformat2_1) struct and do the low level work yourself – David Heffernan Sep 19 '19 at 08:55
  • Thank you David Heffernan. You comment helped me to find the answer on another website. I will post it here. – pyfyc Sep 20 '19 at 07:11

1 Answers1

1

This code works exactly how I expected:

procedure TMainForm.NumberingButtonClick(Sender: TObject);
var
  i: Integer;
  s: String;
  fmt: TParaFormat2;
begin
  FillChar(fmt, SizeOf(fmt), 0);
  fmt.cbSize := SizeOf(fmt);
  fmt.dwMask := PFM_NUMBERING or PFM_NUMBERINGSTART or
                PFM_NUMBERINGSTYLE or PFM_NUMBERINGTAB;
  if NumberingButton.Down then
    fmt.wNumbering := 2
   else
    fmt.wNumbering := 0;
  // wNumbering:
  // 0 - no numbering
  // 1 - bullet list             (·, ·, ·, ...).
  // 2 - Arabic numbers          (1, 2, 3, ...).
  // 3 - small letters           (a, b, c, ...).
  // 4 - capital letters         (A, B, C, ...).
  // 5 - small Roman numbers     (i, ii, iii, ...).
  // 6 - capital Roman numbers   (I, II, III, ...).
  // 7 - Unicode character sequence
  fmt.wNumberingStart := 1;
  // wNumberingStart:
  //  The number at which the numbering starts.
  fmt.wNumberingStyle := $200;
  // wNumberingStyle:
  // Numbering Style
  // 0     :  1)
  // $100  : (1)
  // $200  :  1.
  // $300  :  1
  // $400  : remove list
  // $8000 : continues to number the list without changing the style
  fmt.wNumberingTab := 1440 div 4;
  // wNumberingTab:
  // the space between number and paragraph text
  Editor.Perform( EM_SETPARAFORMAT, 0, lParam( @fmt ) );
  if BulletsButton.Down then
    BulletsButton.Down := False;
end;

enter image description here

Thanks to www.decoding.dax.ru

pyfyc
  • 127
  • 2
  • 9