Recent

Author Topic: TKMemo: Scrollbars = ssBoth does not work  (Read 3303 times)

rvk

  • Hero Member
  • *****
  • Posts: 6643
Re: TKMemo: Scrollbars = ssBoth does not work
« Reply #15 on: January 09, 2025, 11:39:33 am »
For me, it does not work, with or without
Which OS?

rvk

  • Hero Member
  • *****
  • Posts: 6643
Re: TKMemo: Scrollbars = ssBoth does not work
« Reply #16 on: January 09, 2025, 11:47:34 am »
For me it works in Windows.

Maybe you can try to load the data first in a TStringList.
With first setting the TStringList.SkipLastLineBreak to true.

And then do:
Code: Pascal  [Select][+][-]
  1. Memo1.Lines := SL;

That seems to circumvent the mechanisme which TMemo uses to adds the text which adds that #13#10 at the end.

Besides, I think that Memo1.Lines.Text := Copy(Memo1.Lines.Text, 1, Length(Memo1.Lines.Text) - Length(#13#10)); will cause loss of formatting.[/size]
WAIT... Formatting??? Are you using TMemo ???????

Does TKMemo have formatting? TMemo doesn't.

rvk

  • Hero Member
  • *****
  • Posts: 6643
Re: TKMemo: Scrollbars = ssBoth does not work
« Reply #17 on: January 09, 2025, 11:58:47 am »
Besides, I think that Memo1.Lines.Text := Copy(Memo1.Lines.Text, 1, Length(Memo1.Lines.Text) - Length(#13#10)); will cause loss of formatting.[/size]
WAIT... Formatting??? Are you using TMemo ???????

Does TKMemo have formatting? TMemo doesn't.
BTW. This also works for TRichMemo for me on Windows.

Code: Pascal  [Select][+][-]
  1.   RichMemo1.Text := 'abc';
  2.   RichMemo1.Lines.Add('v');
  3.   if RichMemo1.Lines.Text.EndsWith(#13#10) then
  4.     RichMemo1.Lines.Text := Copy(RichMemo1.Lines.Text, 1, Length(RichMemo1.Lines.Text) - Length(#13#10));

BTW. Loading a file in TRichMemo where there is no blank line at the end, it will also not show a blank line in TRichMemo.
So I'm not sure what's going on with your source.
« Last Edit: January 09, 2025, 12:15:09 pm by rvk »

CM630

  • Hero Member
  • *****
  • Posts: 1221
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: TKMemo: Scrollbars = ssBoth does not work
« Reply #18 on: January 09, 2025, 12:32:07 pm »
Besides, I think that Memo1.Lines.Text := Copy(Memo1.Lines.Text, 1, Length(Memo1.Lines.Text) - Length(#13#10)); will cause loss of formatting.
WAIT... Formatting??? Are you using TMemo ???????

Does TKMemo have formatting? TMemo doesn't.
Yes, I am talking about RichMemo, as I wrote a couple of posts above.
TKMemo has formatting. I used it extensively until 5 years ago, IMHO it is much more powerful than TRichMemo, alas it is difficult to use.
But still, it does not work for me:
« Last Edit: January 09, 2025, 12:34:31 pm by CM630 »
Лазар 4,0RC2 32 bit (sometimes 64 bit); FPC3,2,2

rvk

  • Hero Member
  • *****
  • Posts: 6643
Re: TKMemo: Scrollbars = ssBoth does not work
« Reply #19 on: January 09, 2025, 12:39:42 pm »
But still, it does not work for me:
Really really strange.
I just tried it with 3.6 (I'm normally on trunk).
But it still works for me. With exactly the same lines as you have there, I have no blank line at the bottom (under v).

Could you test loading a text-file (.txt not .rtf) with no extra line at the bottom?
Code: Pascal  [Select][+][-]
  1.   RichMemo1.Lines.LoadFromFile('c:\temp\test.txt');
This also results in a TRichMemo without extra line at the bottom.

rvk

  • Hero Member
  • *****
  • Posts: 6643
Re: TKMemo: Scrollbars = ssBoth does not work
« Reply #20 on: January 09, 2025, 12:46:55 pm »
But still, it does not work for me:
I just tried your source.
Somehow you have only #13 as linebreaks. Not #13#10.

So if you do this it should work:

Code: Pascal  [Select][+][-]
  1.   if RichMemo1.Lines.Text.EndsWith(#13) then
  2.     RichMemo1.Lines.Text := Copy(RichMemo1.Lines.Text, 1, Length(RichMemo1.Lines.Text) - Length(#13));

But... if you load a file without a linebreak at the end... it will also work.
It's just that if that file has a linebreak at the end... it will also load in the TRichMemo.

Did you set or change the #13#10 to #13 somewhere? Because when I tried it with a clean project, the #13#10 worked for me.

rvk

  • Hero Member
  • *****
  • Posts: 6643
Re: TKMemo: Scrollbars = ssBoth does not work
« Reply #21 on: January 09, 2025, 12:50:05 pm »
O wow, I figured it out.
I did this in FormCreate.

It seems that in FormCreate the linebreak for TRichMemo is still set at #13#10.

When doing this in a ButtomClick it's at #13.

So this should work:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. begin
  3.   // you can remove this.
  4. end;
  5.  
  6. procedure TForm1.Button1Click(Sender: TObject);
  7. begin
  8.     RichMemo1.Text := 'abc';
  9.     RichMemo1.Lines.Add('v');
  10.     if RichMemo1.Lines.Text.EndsWith(#13) then
  11.       RichMemo1.Lines.Text := Copy(RichMemo1.Lines.Text, 1, Length(RichMemo1.Lines.Text) - Length(#13));
  12. end;

So we should remember that linebreak in TRichMemo is still at #13#10 and it somehow changes when the form is shown  %) ::)

CM630

  • Hero Member
  • *****
  • Posts: 1221
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: TKMemo: Scrollbars = ssBoth does not work
« Reply #22 on: January 09, 2025, 03:33:52 pm »

Thanks, it works.
So I decided to check how it will affect formatting.
So I did:


Code: Pascal  [Select][+][-]
  1. uses
  2.   ...RichMemoUtils... ;
  3.  
  4.  
  5. procedure TForm1.Button1Click(Sender: TObject);
  6. var
  7.   prms : TFontParams;
  8. begin
  9.   prms := GetFontParams(RichMemo1.Font);
  10.   prms.Color := clBlue;
  11.   prms.Style := [fsBold];
  12.  
  13.  
  14.   RichMemo1.Text := 'abc';
  15.   RichMemo1.Lines.Add('v');
  16.   InsertFontText(RichMemo1,'hello world blue', prms);
  17.     RichMemo1.Lines.Add('');
  18.   prms.Color := clGreen;
  19.   InsertFontText(RichMemo1,'hello world green', prms);
  20.   {if RichMemo1.Lines.Text.EndsWith(#13) then
  21.     RichMemo1.Lines.Text := Copy(RichMemo1.Lines.Text, 1, Length(RichMemo1.Lines.Text) - Length(#13));}
  22. end;

I am not sure why I have commented the last two lines, but it occurs that InsertFontText does not add an #13 on the end. :o
So uncommenting the last two lines changes nothing, the IF is FALSE so the Copy(...) is not executed.
Лазар 4,0RC2 32 bit (sometimes 64 bit); FPC3,2,2

rvk

  • Hero Member
  • *****
  • Posts: 6643
Re: TKMemo: Scrollbars = ssBoth does not work
« Reply #23 on: January 09, 2025, 03:40:24 pm »
I am not sure why I have commented the last two lines, but it occurs that InsertFontText does not add an #13 on the end. :o
So uncommenting the last two lines changes nothing, the IF is FALSE so the Copy(...) is not executed.
Yes. When doing TRichMemo.Lines.Add it goes through TStringList and somehow, when receiving it back, it add the #13(#10).
In that case you do need to remove the #13(#10).

But when doing InsertFontText it uses TRichMemo.InDelText which directly adds the text and doesn't add the #13(#10).

CM630

  • Hero Member
  • *****
  • Posts: 1221
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: TKMemo: Scrollbars = ssBoth does not work
« Reply #24 on: January 09, 2025, 04:20:53 pm »
..
Yes. When doing TRichMemo.Lines.Add it goes through TStringList and somehow, when receiving it back, it add the #13(#10).
In that case you do need to remove the #13(#10).

But when doing InsertFontText it uses TRichMemo.InDelText which directly adds the text and doesn't add the #13(#10).
So I wonder if it is a bug. Shall I report it?
Лазар 4,0RC2 32 bit (sometimes 64 bit); FPC3,2,2

rvk

  • Hero Member
  • *****
  • Posts: 6643
Re: TKMemo: Scrollbars = ssBoth does not work
« Reply #25 on: January 09, 2025, 04:37:53 pm »
So I wonder if it is a bug. Shall I report it?
No it's not a bug.
It's documented that TRichMemo.Lines.Add should add the linebreak because when if it doesn't, the following Lines.Add would put everything on the same line.

So it's not a bug. It's normal that you have a new line at the bottom (so users can put the cursor there to begin typing a new line).
It's just that you didn't want that new line (which doesn't happen often).

The only thing that could be considered a bug is how the TStringList (the TRichMemo.Lines) is transported back to TRichMemo itself. It doesn't adhere to the  TStringList.SkipLastLineBreak := true and always puts a linebreak at the end... unless you directly use the TRichMemo.Lines.Text property.
« Last Edit: January 09, 2025, 04:39:51 pm by rvk »

 

TinyPortal © 2005-2018