Recent

Author Topic: Scrool to a position in a Memo(Solved)  (Read 2537 times)

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Scrool to a position in a Memo(Solved)
« on: September 29, 2021, 06:07:42 am »
Trying to scroll to a position in a memo.
This code dose nothing.
What am I missing?
Thanks


Code: Pascal  [Select][+][-]
  1. procedure TForm1.ListBox1Click(Sender: TObject);
  2.    Var i : Integer;
  3.    Item : String;
  4.   begin
  5.     i := ListBox1.ItemIndex;
  6.     if i = -1 then exit;
  7.     Item := Listbox1.Items[ i ];
  8.     Item := Item + ':';
  9.     Memo1.selstart:= Pos(Item,Memo1.text)-1;
  10.     Memo1.SelLength:=0;
  11.     Memo1.SetFocus;;
  12.   end;              
« Last Edit: September 29, 2021, 02:18:26 pm by JLWest »
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2020
  • Former Delphi 1-7, 10.2 user
Re: Scrool to a position in a Memo
« Reply #1 on: September 29, 2021, 06:33:45 am »
Works for me - see pic (I changed Memo1.SelLength:=0; to :=2 to show search hit)
« Last Edit: September 29, 2021, 06:36:43 am by trev »

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Re: Scrool to a position in a Memo
« Reply #2 on: September 29, 2021, 06:52:30 am »
@trev

Not here.

I attached a self contained demo;
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

bytebites

  • Hero Member
  • *****
  • Posts: 633
Re: Scrool to a position in a Memo
« Reply #3 on: September 29, 2021, 08:40:58 am »
Code: Pascal  [Select][+][-]
  1.   Item := Item + ':';

The listbox items have colon padded "Item1:".

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2020
  • Former Delphi 1-7, 10.2 user
Re: Scrool to a position in a Memo
« Reply #4 on: September 29, 2021, 09:34:01 am »
@JLWest: I compiled my macOS trivial demo program on Windows 10 and it still works. I've attached the trivial project. Does this work for you? It does for me.

As bytebites says, in your demo you've added the colon to the Item once in the original listbox text and again in the onlick handler which is why that fails.
« Last Edit: September 29, 2021, 09:40:23 am by trev »

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Re: Scrool to a position in a Memo
« Reply #5 on: September 29, 2021, 10:04:44 am »
Yea, I think it works.

Thanks all.
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

 

TinyPortal © 2005-2018