Recent

Author Topic: Why does this happen  (Read 677 times)

Ten_Mile_Hike

  • Full Member
  • ***
  • Posts: 104
Why does this happen
« on: May 19, 2025, 10:20:59 pm »
Why does the following code produce Tmemo lines 
as short as 7 to as long as 26 characters when
wordwrap is on?

There are no #13 or #10 chars in the string- S
The font is monospaced
Attached is a picture of Tmemo

Code: Pascal  [Select][+][-]
  1. var
  2.   S:String='';
  3. begin
  4. Repeat
  5.     S:=S+Chr(Random(95)+32);  //32..126
  6.   until Length(S)>10000 ;
  7.   Memo1.Text:=S;
  8. end;
When any government, or any church for that matter, undertakes to say to its subjects, This you may not read, this you
must not see, this you are forbidden to know, the end result is tyranny and oppression no matter how holy the motives.

Robert A. Heinlein

Fibonacci

  • Hero Member
  • *****
  • Posts: 754
  • Internal Error Hunter
Re: Why does this happen
« Reply #1 on: May 19, 2025, 10:28:37 pm »
Because there has to be a line break somewhere, and the preferred place is a space character (32)

Bart

  • Hero Member
  • *****
  • Posts: 5573
    • Bart en Mariska's Webstek
Re: Why does this happen
« Reply #2 on: May 19, 2025, 10:31:02 pm »
And if there are no suitable breaking characters, Windows will break the line where it sees fit.

Bart

Ten_Mile_Hike

  • Full Member
  • ***
  • Posts: 104
Re: Why does this happen
« Reply #3 on: May 19, 2025, 11:00:48 pm »
A simple fix for uniform line lengths is
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender:TObject);
  2. var x:Integer; s1,s2:String;
  3. begin
  4.   s1:='';
  5.   s2:='';
  6.   Memo1.Clear;
  7.   Repeat
  8.     S1:=S1+Chr(Random(95)+32);  //32..126
  9.   until Length(S1)>=10000;
  10.   For x:=1 To Length(S1) Do
  11.     Begin
  12.     s2:=s2+s1[x];
  13.     if x mod 20=0 then s2:=s2+#13#10;
  14.     end;
  15.   Memo1.Text:=S2;
  16.   end;

But I never knew that #32 could be used as a line break by windows
When any government, or any church for that matter, undertakes to say to its subjects, This you may not read, this you
must not see, this you are forbidden to know, the end result is tyranny and oppression no matter how holy the motives.

Robert A. Heinlein

dbannon

  • Hero Member
  • *****
  • Posts: 3377
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Why does this happen
« Reply #4 on: May 20, 2025, 01:47:37 am »
...
But I never knew that #32 could be used as a line break by windows

No, its not being used as a line break, its just a suitable place to insert a line break.

Davo
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

Ten_Mile_Hike

  • Full Member
  • ***
  • Posts: 104
Re: Why does this happen
« Reply #5 on: May 20, 2025, 07:26:51 am »
To be clear; is this a Windows thing or a TMemo thing?
When any government, or any church for that matter, undertakes to say to its subjects, This you may not read, this you
must not see, this you are forbidden to know, the end result is tyranny and oppression no matter how holy the motives.

Robert A. Heinlein

Thaddy

  • Hero Member
  • *****
  • Posts: 17176
  • Ceterum censeo Trump esse delendam
Re: Why does this happen
« Reply #6 on: May 20, 2025, 08:37:26 am »
The maximum line length in a Windows textbox, which is the underlying widget on windows is 32,767. But note it may be affected by scrollbar settings.
In effect, that means that within limits it should not be Windows but the TMemo implementation.
« Last Edit: May 20, 2025, 08:38:57 am by Thaddy »
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

 

TinyPortal © 2005-2018