Forum > RichMemo

Length of text in a RichMemo

(1/4) > >>

simsee:
Consider the following code. A TStringList is created and a content is assigned to it

 
--- 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";}};} ---Code.Text: = '123456';
The same content is then assigned to a TRichMemo


--- 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";}};} ---RichMemo1.Lines.Text: = Code.Text;
Why


--- 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";}};} ---ShowMessage (Length (Code.Text) .ToString + ':' + Length (RichMemo1.Lines.Text) .ToString);
shows two different values (8 and 7)?


--- 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";}};} ---unit Unit1; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, RichMemo; type   { TForm1 }   TForm1 = class(TForm)    RichMemo1: TRichMemo;    procedure FormCreate(Sender: TObject);    procedure FormDestroy(Sender: TObject);    procedure RichMemo1Click(Sender: TObject);  private    Code : TStringList;  public   end; var  Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.FormCreate(Sender: TObject);begin  Code:=TStringList.Create;  Code.Text:='123456';  RichMemo1.Lines.Text:=Code.Text;end; procedure TForm1.FormDestroy(Sender: TObject);begin  Code.Free;end; procedure TForm1.RichMemo1Click(Sender: TObject);begin  ShowMessage(Length(Code.Text).ToString+':'+Length(RichMemo1.Lines.Text).ToString);end; end.
Thanks.

KodeZwerg:
I have not tested but does that also happen when you do the same but limit it for the current string?
".text" gives back everyting inside object, stringlists use #00 at end of each element AFAIK, richtext can contain invisible data like settings.

simsee:
Under Windows, It seems that TStringList uses CR+LF as a line terminator, while TRichMemo only uses CR.

I'm not sure if this behavior is correct. Let's say I didn't expect it.

dsiders:

--- Quote from: simsee on October 19, 2022, 05:18:52 pm ---Under Windows, It seems that TStringList uses CR+LF as a line terminator, while TRichMemo only uses CR.

I'm not sure if this behavior is correct. Let's say I didn't expect it.

--- End quote ---

It uses the native EOL sequence for the platform or OS. You can use the LineBreak property to change it if desired..

simsee:
Under Windows TRichMemo.Lines.Text uses CR as EOL. It not use CR+LF as it should be.

Navigation

[0] Message Index

[#] Next page

Go to full version