* * *

Author Topic: Bug: If I Modify memo.seltext cursor goes to top... Why?  (Read 6451 times)

maaah

  • New member
  • *
  • Posts: 14
    • Via Mep
Bug: If I Modify memo.seltext cursor goes to top... Why?
« on: June 13, 2010, 10:18:12 pm »
Title says all I mean. Here is a screen video:

http://www.viamep.com/share/lazarus-bug-editor-seltext-cursor-goes-top.wmv

(11 MB, 4 min, 1680x1050)

I'm using Memo. If I have this:

memo1.seltext := 'something...' + memo1.seltext + 'hello world';

Cursor goes to top. I think there is a bug in win32/64 Lazarus implementation of system Memo.
Looking for a new and fast music player? Get Mondego! It's free: http://bit.ly/bnSr58
Mep Texto 8: text editor made with Lazarus :) http://bit.ly/7jWwW0
Ajuda do Mep Installer / Inno Setup em português: http://bit.ly/cKUFqN

Mr.Paul

  • Newbie
  • Posts: 3
  • 一次编写,到处编译
Re: Bug: If I Modify memo.seltext cursor goes to top... Why?
« Reply #1 on: March 26, 2013, 05:20:04 pm »
I met the Similar problem , on  two years later.   The environment is: Lazarus 1.0.8 on Windows XP.

When more strings words within the memo, that is, the vertical scroll bar appears, then executed:
Code: [Select]
    Memo1.SelText: = 'some + words';      // it works + but ...
Scroll bar will goto the top !?
Puzzling is the insertion point cursor, still on position of seltext.
« Last Edit: March 26, 2013, 06:26:43 pm by Mr.Paul »

howardpc

  • Hero Member
  • *****
  • Posts: 2388
Re: Bug: If I Modify memo.seltext cursor goes to top... Why?
« Reply #2 on: March 26, 2013, 05:51:12 pm »
A simple workaround for situations you know will move the cursor where you don't want it to go, is to save the value of CaretPos before the code in question, and restore it (immediately after that code executes) to its original value.

Mr.Paul

  • Newbie
  • Posts: 3
  • 一次编写,到处编译
Re: Bug: If I Modify memo.seltext cursor goes to top... Why?
« Reply #3 on: March 26, 2013, 06:07:53 pm »
Thanks for reply, but I did not succeed:
Code: [Select]
var old:Tpoint;
begin
  old:=memo1.CaretPos;
  Memo1.SelText: = 'some + words';
  Memo1.caretPos:=old;
end;
It should be noted, CaretPos always been correct.
Incorrect position of the scrollbar, memo shows the location of the text is.
« Last Edit: March 26, 2013, 06:17:09 pm by Mr.Paul »

u2o

  • Jr. Member
  • **
  • Posts: 64
  • No message
Re: Bug: If I Modify memo.seltext cursor goes to top... Why?
« Reply #4 on: April 07, 2013, 03:00:33 am »
Hi! Try

Code: [Select]
var
  old: Integer;
begin
  old := Memo1.SelStart  ;
  Memo1.SelText := 'some' + Memo1.SelText + 'words';
  Memo1.SelStart := old;
  Memo1.SetFocus ;
end;

The scrollbar is moved to the selected line...

fedkad

  • New member
  • *
  • Posts: 29
Re: Bug: If I Modify memo.seltext cursor goes to top... Why?
« Reply #5 on: September 03, 2016, 06:19:32 pm »
I have met the same problem. However, the workaround posted by u2o is not a perfect solution, because scrollbar still moves up, but as much as possible, so that the SelStart point is displayed at the bottom of the memo.

Detailed explanation:
On a long memo with vertical scroll bar and which has more data that can fit on its viewable area, when the vertical scroll bar is at the top and you make something like Memo.SelText := 'blabla'; there is no problem. If you make a change when to scroll bar is not at the top, the scroll bar moves to the top regardless of the position of the SelStart point, which in some cases moves out of the scope.

If you use a workaround like Memo.SelStart := Memo.SelStart; the scrollbar still tries to move to the top, but this movement is as much as the selection point stays in view, but at the bottom (last line) of the viewable area of the memo.

Normally no movement should occur, as in Delphi.


 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus