Forum > RichMemo

Numbered list in RichMemo

<< < (2/4) > >>

rvk:

--- Quote from: Thaddy on July 31, 2023, 06:43:55 pm ---It works, provided the paragraph is defined.

--- End quote ---
Yes. And I provided code for that.
The code for defining the paragraph was already in the attachment.
Only the code for adding text for a new number is needed.

If you have different code you can show it.

paxnet_be:
"RichMemo1.Text is a text representation of your RTF without formatting.
So when assigning that back to RichMemo1.Text you'll loose all formatting"

Thank you for pointing that, rvk. I think, I better can use SetParaNumbering() with style pnNone.

When I use SelLength > 0 and a list item (see attachment), then I become:
  1. (no listitem)
  2.(no listitem)

and i cannot add numbered items. So I still don't get how the automatic numbering works.

Can you provide me a working example?

rvk:

--- Quote from: paxnet_be on August 01, 2023, 12:50:09 pm ---Can you provide me a working example?

--- End quote ---
Here is an example.

Result looks like the image blow (this is all added in code).


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.Button1Click(Sender: TObject);var  pn: TParaNumbering;  pm: TParaMetric;  ListItem: String;begin  RichMemo1.Clear;  RichMemo1.Lines.Add('This is just some text');  RichMemo1.Lines.Add('This is just some text');  RichMemo1.Lines.Add('This is just some text');  RichMemo1.Lines.Add('This is just some text');   InitParaNumbering(pn);  InitParaMetric(pm);  RichMemo1.GetParaNumbering(0, pn);  RichMemo1.GetParaMetric(0, pm);   // setup the new numbering list from current position  pn.Style := pnNumber;  pn.Indent := 14;  pn.NumberStart := 1;  pn.SepChar := SepDot;  pm.FirstLine := 24;   RichMemo1.SelStart := Length(RichMemo1.Lines.Text);   // we can use 0 here because everything from this point  // onwards is numberlist  RichMemo1.SetParaNumbering(RichMemo1.SelStart, 0, pn);  RichMemo1.SetParaMetric(RichMemo1.SelStart, 0, pm);   ListItem := 'First item';  RichMemo1.SelStart := Length(RichMemo1.Lines.Text);  RichMemo1.SelLength := 0;  RichMemo1.SelText := ListItem;  RichMemo1.SelLength := 0;   ListItem := 'Second item';  RichMemo1.SelStart := Length(RichMemo1.Lines.Text);  RichMemo1.SelLength := 0;  RichMemo1.SelText := #13 + ListItem;  RichMemo1.SelLength := 0;   ListItem := 'Third item';  RichMemo1.SelStart := Length(RichMemo1.Lines.Text);  RichMemo1.SelLength := 0;  RichMemo1.SelText := #13 + ListItem;  RichMemo1.SelLength := 0;  end;

paxnet_be:
Thank you rvk for your example.
Now it becomes clear to me, how I have to add my list.

I copied your code to my MenuItem procedure to test it. However, I have a strange result (see picture in attachment): only the first list item is numbered.

For more information, I running Lazarus 2.2.6 on a Linux openSUSE 15.4 with 12 GB memory.

rvk:

--- Quote from: paxnet_be on August 01, 2023, 03:15:48 pm ---Now it becomes clear to me, how I have to add my list.
--- End quote ---
If you put my code under a button, does it work on openSUSE?

If not, then there is something fishy with openSUSE.

If it does, then there is something wrong with your code.
You need to put the SelStart right after the last numbered line.
NOT below it.

If you put it below it, the numbering won't work anymore.
If you put it after the last numbered item and add the new item with #13 in front,
it will act just like you typed it (enter and then text).

It's the same with ending a line with BOLD text.
If you begin typing on a new line, you don't get BOLD.
If you go to the end of the last line with BOLD and you press enter, and then text, you do get BOLD.

It's the same with the numbering, you need to start at the end of the last numbered line (and add #13 + text).

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version