Recent

Author Topic: Numbered list in RichMemo  (Read 6966 times)

paxnet_be

  • New Member
  • *
  • Posts: 22
Numbered list in RichMemo
« on: July 31, 2023, 03:17:25 pm »
Hi,
I'm trying to set a numbered list in RichMemo, but I'm stuck with the numbering:
after creating successfully the first list item, the number stays on 1 and does not increase.
I don't know how to solve it. Can someone help me?
Thanks in advance.
Now I know you never know, but at least I know this. - Jean Gabin

rvk

  • Hero Member
  • *****
  • Posts: 6944
Re: Numbered list in RichMemo
« Reply #1 on: July 31, 2023, 05:10:37 pm »
I'm not sure what you are trying to accomplish with this line:
Code: Pascal  [Select][+][-]
  1. RichMemo1.Text := RichMemo1.Text + ListItem;

But that line strips the Text from ALL formatting.
RichMemo1.Text is a text representation of your RTF without formatting.
So when assigning that back to RichMemo1.Text you'll loose all formatting.

If you want to add a line to the current listitem you could use
Code: Pascal  [Select][+][-]
  1. RichMemo1.Lines.Add(ListItem);

If you want to create a complete new listitem you can do:
Code: Pascal  [Select][+][-]
  1. var
  2.   ListItem: String;
  3. begin
  4.   ListItem := 'New bullet';
  5.   RichMemo1.SelLength := 0;
  6.   RichMemo1.SelText := #13 + ListItem;
  7.   RichMemo1.SelLength := 0;

Thaddy

  • Hero Member
  • *****
  • Posts: 18729
  • To Europe: simply sell USA bonds: dollar collapses
Re: Numbered list in RichMemo
« Reply #2 on: July 31, 2023, 06:27:23 pm »
You can use TrichMemo.SetRangeParaNumbering. pnBullet is the bullet style and pnNumber is the numbered style.
If Europe sells their USA bonds the USD will collapse. Europe can affort that given average state debts. The USA can't affort that. Just an advice...

rvk

  • Hero Member
  • *****
  • Posts: 6944
Re: Numbered list in RichMemo
« Reply #3 on: July 31, 2023, 06:33:37 pm »
You can use TrichMemo.SetRangeParaNumbering. pnBullet is the bullet style and pnNumber is the numbered style.
He wants a numberstyle, as stated in the question !!
That works... but when adding text (as done in the supplied code) the number doesn't increase.


Thaddy

  • Hero Member
  • *****
  • Posts: 18729
  • To Europe: simply sell USA bonds: dollar collapses
Re: Numbered list in RichMemo
« Reply #4 on: July 31, 2023, 06:43:55 pm »
It works, provided the paragraph is defined.
If Europe sells their USA bonds the USD will collapse. Europe can affort that given average state debts. The USA can't affort that. Just an advice...

rvk

  • Hero Member
  • *****
  • Posts: 6944
Re: Numbered list in RichMemo
« Reply #5 on: July 31, 2023, 06:49:34 pm »
It works, provided the paragraph is defined.
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.
« Last Edit: July 31, 2023, 06:51:54 pm by rvk »

paxnet_be

  • New Member
  • *
  • Posts: 22
Re: Numbered list in RichMemo
« Reply #6 on: August 01, 2023, 12:50:09 pm »
"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?
« Last Edit: August 01, 2023, 12:54:56 pm by paxnet_be »
Now I know you never know, but at least I know this. - Jean Gabin

rvk

  • Hero Member
  • *****
  • Posts: 6944
Re: Numbered list in RichMemo
« Reply #7 on: August 01, 2023, 01:54:27 pm »
Can you provide me a working example?
Here is an example.

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

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var
  3.   pn: TParaNumbering;
  4.   pm: TParaMetric;
  5.   ListItem: String;
  6. begin
  7.   RichMemo1.Clear;
  8.   RichMemo1.Lines.Add('This is just some text');
  9.   RichMemo1.Lines.Add('This is just some text');
  10.   RichMemo1.Lines.Add('This is just some text');
  11.   RichMemo1.Lines.Add('This is just some text');
  12.  
  13.   InitParaNumbering(pn);
  14.   InitParaMetric(pm);
  15.   RichMemo1.GetParaNumbering(0, pn);
  16.   RichMemo1.GetParaMetric(0, pm);
  17.  
  18.   // setup the new numbering list from current position
  19.   pn.Style := pnNumber;
  20.   pn.Indent := 14;
  21.   pn.NumberStart := 1;
  22.   pn.SepChar := SepDot;
  23.   pm.FirstLine := 24;
  24.  
  25.   RichMemo1.SelStart := Length(RichMemo1.Lines.Text);
  26.  
  27.   // we can use 0 here because everything from this point
  28.   // onwards is numberlist
  29.   RichMemo1.SetParaNumbering(RichMemo1.SelStart, 0, pn);
  30.   RichMemo1.SetParaMetric(RichMemo1.SelStart, 0, pm);
  31.  
  32.   ListItem := 'First item';
  33.   RichMemo1.SelStart := Length(RichMemo1.Lines.Text);
  34.   RichMemo1.SelLength := 0;
  35.   RichMemo1.SelText := ListItem;
  36.   RichMemo1.SelLength := 0;
  37.  
  38.   ListItem := 'Second item';
  39.   RichMemo1.SelStart := Length(RichMemo1.Lines.Text);
  40.   RichMemo1.SelLength := 0;
  41.   RichMemo1.SelText := #13 + ListItem;
  42.   RichMemo1.SelLength := 0;
  43.  
  44.   ListItem := 'Third item';
  45.   RichMemo1.SelStart := Length(RichMemo1.Lines.Text);
  46.   RichMemo1.SelLength := 0;
  47.   RichMemo1.SelText := #13 + ListItem;
  48.   RichMemo1.SelLength := 0;
  49.  
  50.  
  51. end;

paxnet_be

  • New Member
  • *
  • Posts: 22
Re: Numbered list in RichMemo
« Reply #8 on: August 01, 2023, 03:15:48 pm »
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.

Now I know you never know, but at least I know this. - Jean Gabin

rvk

  • Hero Member
  • *****
  • Posts: 6944
Re: Numbered list in RichMemo
« Reply #9 on: August 01, 2023, 03:34:17 pm »
Now it becomes clear to me, how I have to add my list.
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).

paxnet_be

  • New Member
  • *
  • Posts: 22
Re: Numbered list in RichMemo
« Reply #10 on: August 01, 2023, 05:44:30 pm »
Tested with a button --> same result.
Tested in a VM with openSUSE 15.4 and Lazarus 2.2 --> same result.
Tested in a VM Win10 and Lazarus 2.2 --> works.

It seems that my SUSE sucks, but is it only with SUSE or with other Linux distributions too?
Now I know you never know, but at least I know this. - Jean Gabin

rvk

  • Hero Member
  • *****
  • Posts: 6944
Re: Numbered list in RichMemo
« Reply #11 on: August 01, 2023, 10:45:48 pm »
If I get some time tomorrow I can test it on some Linux version.

Does it work if you just type it yourself?
So does enter give you a new number manually?

If not, then the whole numbering didn't work on Linux.
But maybe it's just a question of positioning the start correctly.


Curt Carpenter

  • Hero Member
  • *****
  • Posts: 717
Re: Numbered list in RichMemo
« Reply #12 on: August 02, 2023, 04:31:38 am »
I was working with RichMemo a few months ago trying to make an old Lazarus program work on both Win and Linux.  For what it's worth, I ended up making multiple compromises and work-arounds to make the Linux version of my code work using the RichMemo component from the OPM here.  I don't think it's your OS -- it's a Linux component problem (or maybe a widget set problem) (or, of course, an operator problem...).  As an example, as I recall the use of CR/LF pairs is different between the Windows and Linux versions of the component.   

paxnet_be

  • New Member
  • *
  • Posts: 22
Re: Numbered list in RichMemo
« Reply #13 on: August 02, 2023, 09:01:46 am »
@rvk
Quote
So does enter give you a new number manually?

Enter gives me a new line without indentation or number...

@Curt Carpenter
Quote
the use of CR/LF pairs is different between the Windows and Linux versions
I use LineEnding (unit System), it works OS-dependent.
Now I know you never know, but at least I know this. - Jean Gabin

rvk

  • Hero Member
  • *****
  • Posts: 6944
Re: Numbered list in RichMemo
« Reply #14 on: August 02, 2023, 10:14:38 am »
Quote
So does enter give you a new number manually?
Enter gives me a new line without indentation or number...
Ok, then it's not much use to look at this.

If automatic numbering when pressing manual enter doesn't even work, then it just doesn't work on Linux.

I'm not sure which underlying Linux OS widget handles the richedit-part but apparently that part just doesn't handle numbering correctly.

 

TinyPortal © 2005-2018