Recent

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

CM630

  • Hero Member
  • *****
  • Posts: 1265
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
TKMemo: Scrollbars = ssBoth does not work
« on: January 08, 2025, 07:55:25 am »
When I set Scrollbars = ssBoth of a TKMemo it works as ssAutoBoth.
The scrollbars are shown only when the text cannot fit into the memo horizontally or vertically.
Is there a way to make the scrollbars always visible?
Лазар 4,0RC2 32 bit (sometimes 64 bit); FPC3,2,2

rvk

  • Hero Member
  • *****
  • Posts: 6675
Re: TKMemo: Scrollbars = ssBoth does not work
« Reply #1 on: January 08, 2025, 10:22:44 am »
Same goes for horizontal and vertical scrollbars.

I don't think TKMemo implemens the ssAuto* at all.
It only does ssBoth, ssVertical and ssHorizontal.
And they are all "auto".

BTW. I don't think you should use ssAuto* in TKMemo because it just doesn't do anything (i.e. ssAutoBoth doesn't show a scrollbar when the window get too smal).

When using WS_HSCROLL and WS_VSCROLL in CreateWindow(Ex) Windows only creates the scrollbars when needed. Not persistent.

TMemo works with a separate TMemoScrollbar (FVertScrollbar/FHorzScrollbar) for the ssBoth (and other non ssAuto* values).
But it also sets the WS_HSCROLL and WS_VSCROLL for ssBoth.
So I'm not entirely sure how it hides it's own F*Scrollbar when the one for Windows kicks in  %)

But... yes, you need to create your own scrollbar...
You can look at the source for TMemo how it is done there.

CM630

  • Hero Member
  • *****
  • Posts: 1265
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: TKMemo: Scrollbars = ssBoth does not work
« Reply #2 on: January 08, 2025, 02:12:18 pm »
Hmmm,
I tried to use RichMemo, but it occurred that I cannot, because it leaves an empty line after the last one.
I decided to try TKMemo, but it does not create scrollbars  :'(
The good point is that my text is read only, maybe I shall use some HTML widget... maybe I should ask in another thread about a proper component.
Лазар 4,0RC2 32 bit (sometimes 64 bit); FPC3,2,2

rvk

  • Hero Member
  • *****
  • Posts: 6675
Re: TKMemo: Scrollbars = ssBoth does not work
« Reply #3 on: January 08, 2025, 05:45:34 pm »
The good point is that my text is read only, maybe I shall use some HTML widget...
If your text is read only why can't you use TRichMemo?

The scrollbars just always work as auto in TKMemo.
In TMemo it works correctly.
I'm didn't test TRichMemo but do you need RTF text or just have unformated text?

CM630

  • Hero Member
  • *****
  • Posts: 1265
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: TKMemo: Scrollbars = ssBoth does not work
« Reply #4 on: January 09, 2025, 07:43:50 am »
Лазар 4,0RC2 32 bit (sometimes 64 bit); FPC3,2,2

rvk

  • Hero Member
  • *****
  • Posts: 6675
Re: TKMemo: Scrollbars = ssBoth does not work
« Reply #5 on: January 09, 2025, 09:16:28 am »
I cannot use TRichMemo because of this issue: https://forum.lazarus.freepascal.org/index.php/topic,69590.msg540981.html
Can't you do something like this to remove the last #13#10 from the TMemo?

The problem is that normally the TStringList has #13#10 for the last line which results in an extra line in TMemo.
You can just delete that #13#10. At least... this works in Windows.
(So you can do this after loading your text, before showing the window)

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

Thaddy

  • Hero Member
  • *****
  • Posts: 16580
  • Kallstadt seems a good place to evict Trump to.
Re: TKMemo: Scrollbars = ssBoth does not work
« Reply #6 on: January 09, 2025, 11:12:24 am »
Since lines is TStrings it is enough to set Memo.Lines.SkipLastLinebreak := true;.
People tend to forget that all the time.
« Last Edit: January 09, 2025, 11:16:00 am by Thaddy »
But I am sure they don't want the Trumps back...

rvk

  • Hero Member
  • *****
  • Posts: 6675
Re: TKMemo: Scrollbars = ssBoth does not work
« Reply #7 on: January 09, 2025, 11:15:22 am »
Since lines is TStrings it is enough to set Memo.Lines.SkipLastLinebreak := true.
Did you TEST that Thaddy ????  %)

Here, I'll help you.
Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. begin
  3.   Memo1.Lines.SkipLastLineBreak := true;
  4.   Memo1.Lines.Add('a');
  5.   Memo1.Lines.Add('b');
  6.   // if Memo1.Lines.Text.EndsWith(#13#10) then
  7.   //   Memo1.Lines.Text := Copy(Memo1.Lines.Text, 1, Length(Memo1.Lines.Text) - Length(#13#10));
  8. end;

No, you didn't test that  >:D

(BTW. In the other topic it was already discussed that that didn't work)

Thaddy

  • Hero Member
  • *****
  • Posts: 16580
  • Kallstadt seems a good place to evict Trump to.
Re: TKMemo: Scrollbars = ssBoth does not work
« Reply #8 on: January 09, 2025, 11:16:51 am »
Then it is a bug. Even more so it is a regression, because it used to work.
[edit] on store, the last linebreak is skipped, just not on display.
« Last Edit: January 09, 2025, 11:24:15 am by Thaddy »
But I am sure they don't want the Trumps back...

rvk

  • Hero Member
  • *****
  • Posts: 6675
Re: TKMemo: Scrollbars = ssBoth does not work
« Reply #9 on: January 09, 2025, 11:19:09 am »
Then it is a bug
I have a feeling I already discussed this in the past (that TStringList always added the #13#10).
I didn't bother to search but I'm sure I was part of such conversation.

Anyway... manually stripping the #13#10 from the Memo1.Lines.Text does work (because TStringList only adds it during 'getting' of the data, which TMemo doesn't do afterwards anymore unless you change the text again).

Thaddy

  • Hero Member
  • *****
  • Posts: 16580
  • Kallstadt seems a good place to evict Trump to.
Re: TKMemo: Scrollbars = ssBoth does not work
« Reply #10 on: January 09, 2025, 11:25:36 am »
On store the last linebreak is skipped, just not on display. You can easily verify that. Works as intended and most definitely tested. >:D
« Last Edit: January 09, 2025, 11:30:55 am by Thaddy »
But I am sure they don't want the Trumps back...

rvk

  • Hero Member
  • *****
  • Posts: 6675
Re: TKMemo: Scrollbars = ssBoth does not work
« Reply #11 on: January 09, 2025, 11:28:26 am »
On store the last linebreak is skipped, just not on display. You can easily verify that. Works as probably intended.
On store... yes. But not on Read. If you look at the source, I remember there is a GetText where #13#10 is always added at the end.
No check on SkipLastLineBreak and no other option to prohibit that (at least, that's from my memory).


Thaddy

  • Hero Member
  • *****
  • Posts: 16580
  • Kallstadt seems a good place to evict Trump to.
Re: TKMemo: Scrollbars = ssBoth does not work
« Reply #12 on: January 09, 2025, 11:33:07 am »
 There is no bug. It works. From memory is not testing, like I did.
But I am sure they don't want the Trumps back...

rvk

  • Hero Member
  • *****
  • Posts: 6675
Re: TKMemo: Scrollbars = ssBoth does not work
« Reply #13 on: January 09, 2025, 11:34:53 am »
There is no bug. It works. From memory is not testing, like I did.
I meant, did you test your line you gave?
See the code I gave you.
Did it have a blank line below the last non empty line???

See below:
It just doesn't work !!!

Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. begin
  3.   Memo1.Lines.SkipLastLineBreak := true;
  4.   Memo1.Lines.Add('a');
  5.   Memo1.Lines.Add('b');
  6.   // if Memo1.Lines.Text.EndsWith(#13#10) then
  7.   //   Memo1.Lines.Text := Copy(Memo1.Lines.Text, 1, Length(Memo1.Lines.Text) - Length(#13#10));
  8. end;

CM630

  • Hero Member
  • *****
  • Posts: 1265
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: TKMemo: Scrollbars = ssBoth does not work
« Reply #14 on: January 09, 2025, 11:38:45 am »
For me, it does not work, with or without
Code: Pascal  [Select][+][-]
  1.   if Memo1.Lines.Text.EndsWith(#13#10) then
  2.      Memo1.Lines.Text := Copy(Memo1.Lines.Text, 1, Length(Memo1.Lines.Text) - Length(#13#10));



Lazarus 4,0RC1 32 bit; FPC3,2,2 on Win 10 64 bit

Besides, I think that Memo1.Lines.Text := Copy(Memo1.Lines.Text, 1, Length(Memo1.Lines.Text) - Length(#13#10)); will cause loss of formatting.
« Last Edit: January 09, 2025, 11:40:47 am by CM630 »
Лазар 4,0RC2 32 bit (sometimes 64 bit); FPC3,2,2

 

TinyPortal © 2005-2018