Recent

Author Topic: TMemo scroll to end (Linux)?  (Read 6757 times)

HatForCat

  • Sr. Member
  • ****
  • Posts: 293
TMemo scroll to end (Linux)?
« on: June 06, 2019, 11:38:52 pm »
Hi, I have a Memo as a log file. Before a new line adding to the memo I have

Code: Pascal  [Select][+][-]
  1.   while (mem.Lines.Count > 100) do
  2.     mem.Lines.Delete(0);
  3.  

I need to then move the cursor to the end to visually display the new line. All the things I have found so far rely on SendMessage and pretty sure that Lazarus and Ubuntu will not grasp that nettle.

How is it done?

Thanks
Acer-i5, 2.6GHz, 6GB, 500GB-SSD, Mint-19.3, Cinnamon Desktop, Lazarus 2.0.6, SQLite3

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: TMemo scroll to end (Linux)?
« Reply #1 on: June 06, 2019, 11:53:47 pm »
You could try
Code: Pascal  [Select][+][-]
  1. mem.SelStart := Length(mem.Text);

lucamar

  • Hero Member
  • *****
  • Posts: 4217
Re: TMemo scroll to end (Linux)?
« Reply #2 on: June 07, 2019, 03:34:07 am »
Another possibility, if setting SelStart doesn't work

Code: Pascal  [Select][+][-]
  1. Memo.CaretPos := Point(0, Memo.Lines.Count-1)
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

HatForCat

  • Sr. Member
  • ****
  • Posts: 293
Re: TMemo scroll to end (Linux)?
« Reply #3 on: June 07, 2019, 07:58:27 pm »
You could try
Code: Pascal  [Select][+][-]
  1. mem.SelStart := Length(mem.Text);

Thanks, that seems to work fine and keeps the last line visible.
Acer-i5, 2.6GHz, 6GB, 500GB-SSD, Mint-19.3, Cinnamon Desktop, Lazarus 2.0.6, SQLite3

HatForCat

  • Sr. Member
  • ****
  • Posts: 293
Re: TMemo scroll to end (Linux)?
« Reply #4 on: June 07, 2019, 08:04:30 pm »
Code: Pascal  [Select][+][-]
  1. Memo.CaretPos := Point(0, Memo.Lines.Count-1)

Thanks, but I hate to mention, it did not scroll.

Back in the Delphi days I used PlusMemo (paid for) and it had an option "Scroll_Into_View" or something close that. You defined a Line and Scroll_Into_View and it would display the line in the vertical-center of the Memo window, or at the bottom if there was no following Line.

Seems like a nice idea for FPC/Lazarus 2.1. :)
Acer-i5, 2.6GHz, 6GB, 500GB-SSD, Mint-19.3, Cinnamon Desktop, Lazarus 2.0.6, SQLite3

jamie

  • Hero Member
  • *****
  • Posts: 7602
Re: TMemo scroll to end (Linux)?
« Reply #5 on: June 07, 2019, 11:06:49 pm »
I don't know if this is going to work with Linux, it should since it is suppose to be the same
construct for the memo

SendMessage(Memo.Handle, EM_SCROLLCARET, 0,0);

 In windows, that will scroll the window to show the caret, this is done after you set the
caret position.

Memo.SelStart := Length(Memo.Text);
SendMessage(Mem0.Handle, EM_SCROLLCARET, 0, 0);

In windows that scrolls the window like I said in view of the caret.
The only true wisdom is knowing you know nothing

lucamar

  • Hero Member
  • *****
  • Posts: 4217
Re: TMemo scroll to end (Linux)?
« Reply #6 on: June 08, 2019, 02:20:36 am »
Code: Pascal  [Select][+][-]
  1. Memo.CaretPos := Point(0, Memo.Lines.Count-1)

Thanks, but I hate to mention, it did not scroll.

Curious. It works perfectly here (Lazarus 2.0.2 / Ubuntu 12). It's how I implement the "Goto line..." for simple editors:

Code: Pascal  [Select][+][-]
  1. procedure TMainForm.itSearchGotoClick(Sender: TObject);
  2. var
  3.   Line: Integer;
  4.   NewVal: String;
  5. begin
  6. {NOTE: CurrentEditor returns the TMemo instance inside the current tab/page of a TPageControl}
  7.   NewVal := InttoStr(CurrentEditor.CaretPos.y);
  8.   NewVal := InputBox('Goto line ...', 'New line number?', NewVal);
  9.   if TryStrToInt(NewVal, Line) then begin
  10.     if Line > CurrentEditor.Lines.Count then
  11.       Line := CurrentEditor.Lines.Count
  12.     else if Line <= 0 then
  13.       Line := 1;
  14.     CurrentEditor.CaretPos := Point(0, Line-1);{Zero-based, so "-1"}
  15.   end;
  16.   UpdateStatus;
  17. end;
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

HatForCat

  • Sr. Member
  • ****
  • Posts: 293
Re: TMemo scroll to end (Linux)?
« Reply #7 on: June 09, 2019, 10:25:53 pm »
Curious. It works perfectly here (Lazarus 2.0.2 / Ubuntu 12).

Could it be something that was fixed in 2.0.2?

Way off topic here:
I just tried to install 2.0.2 but it still starts 2.0.0. I tried deleting 2.0.0 with Synaptic then 2.0.2 can't find the IDE files. What do I need to do to get 2.0.2 installed without removing it all again?
Acer-i5, 2.6GHz, 6GB, 500GB-SSD, Mint-19.3, Cinnamon Desktop, Lazarus 2.0.6, SQLite3

lucamar

  • Hero Member
  • *****
  • Posts: 4217
Re: TMemo scroll to end (Linux)?
« Reply #8 on: June 10, 2019, 01:27:29 am »
Could it be something that was fixed in 2.0.2?

I don't think so: that code (and similar ones) was working well also with Lazarus 1.6.x and 1.8.x. It may be related to the GTK version ... but it's been working alright on a fairly large range of Linux distros and versions. It's indeed rather curious ...

Quote
Way off topic here:
I just tried to install 2.0.2 but it still starts 2.0.0. I tried deleting 2.0.0 with Synaptic then 2.0.2 can't find the IDE files. What do I need to do to get 2.0.2 installed without removing it all again?

I use a local repository to install Lazarus and other packages that are usualy outdated in the official repos. What I do to update is purge the old versions of Lazarus, FPC and FPC-Sources and install the new ones.

I never had a problem which was not caused by a global (system) misconfiguration but other people seems to find nothing but. Search the forum for "Installing Lazarus on Ubuntu" and you'll see various relatively common problems and the proposed solutions (including mine :))
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

HatForCat

  • Sr. Member
  • ****
  • Posts: 293
Re: TMemo scroll to end (Linux)?
« Reply #9 on: June 10, 2019, 05:04:07 pm »
I never had a problem which was not caused by a global (system) misconfiguration but other people seems to find nothing but.

Thanks, me too and complete clearing was what I have done in the past. But, I was hoping by now this issue had been fixed.

Clearly not enough Linux user to warrant attention! {sigh} ;)
Acer-i5, 2.6GHz, 6GB, 500GB-SSD, Mint-19.3, Cinnamon Desktop, Lazarus 2.0.6, SQLite3

lucamar

  • Hero Member
  • *****
  • Posts: 4217
Re: TMemo scroll to end (Linux)?
« Reply #10 on: June 10, 2019, 05:21:32 pm »
Clearly not enough Linux user to warrant attention! {sigh} ;)

It's not that; the problem is that there is no such thing as a "standard" Linux desktop configuration, so things that work for one person might give problems to another. Even when the environments look the same, say two "normal" Ubuntu X installs, they usually are not and those subtle differences may mean that one can install w/ out problems while the other sweats blood to get it going.

That said, purging completely the old install and instaling the newest debs (the Lazarus ones, not the ones from the distro's repo) usually works, even if you have to use GDebi or get down to "apt install".
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

HatForCat

  • Sr. Member
  • ****
  • Posts: 293
Re: TMemo scroll to end (Linux)?
« Reply #11 on: June 10, 2019, 07:49:55 pm »
instaling the newest debs (the Lazarus ones

if you have to use GDebi

Enthused by your earlier comments, I did that and now I have nothing. {sigh} I used Synaptic to remove both FPC and Lazarus. I deleted the .lazarus folder in home. Rebooted and installed the .debs in the correct sequence.

Now Mint cannot find Lazarus, even if I try from the CL.

From what I can see in the GDebi "More" CLI listing, 2.0.2 is an update to the installed 2.0.0 as it says, "Upgrading to 2.0.2 over 2.0.0" but now I have neither. Damn this is frustrating. This never happens with other software I use, so even if there is no "standard" Lazarus install, pretty much everything C++, Python et al,  seems to be happy with the concept. :)
Acer-i5, 2.6GHz, 6GB, 500GB-SSD, Mint-19.3, Cinnamon Desktop, Lazarus 2.0.6, SQLite3

ezlage

  • Guest
Re: TMemo scroll to end (Linux)?
« Reply #12 on: February 01, 2021, 06:28:37 pm »
I am sorry for resurrecting this topic, but I faced the same problem and it seems that no solution has been given here.

I solved it using TMemo.Append instead of TMemo.Lines.Add/AddText. Using WordWrap it may be necessary to include an empty line at the end, or the position will be the beginning of the line that will be broken only visually. Selecting text can also prevent this, I guess.
« Last Edit: February 01, 2021, 06:34:48 pm by ezlage »

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: TMemo scroll to end (Linux)?
« Reply #13 on: February 01, 2021, 06:50:36 pm »
Hi!


Old lousy trick:
Code: Pascal  [Select][+][-]
  1. Memo.selstart := MaxInt;

The Memo will recognize that MaxInt is too much and set it to the last possible position.

Winni

lucamar

  • Hero Member
  • *****
  • Posts: 4217
Re: TMemo scroll to end (Linux)?
« Reply #14 on: February 01, 2021, 06:54:27 pm »
I am sorry for resurrecting this topic, but I faced the same problem and it seems that no solution has been given here.

We did give a couple solutions at the very start, if you look closely: either setting SelStart or CaretPos. :)

I solved it using TMemo.Append instead of TMemo.Lines.Add/AddText. Using WordWrap it may be necessary to include an empty line at the end, or the position will be the beginning of the line that will be broken only visually.

That's not the same problem about which this thread was, is it? I mean Append and Lines.Add should have the same behaviour, as can be seen from Append's implementation:
Code: Pascal  [Select][+][-]
  1. procedure TCustomMemo.Append(const Value: String);
  2. begin
  3.   Lines.Add(Value);
  4. end;
If they don't for you then something very strange must be happenning...

WorWrap might interfere with caret positioning/lines visibility in some widgetsets but I don't know if adding an empty line just to solve this is worth it ... :-\
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

 

TinyPortal © 2005-2018