Recent

Author Topic: RichMemo Scrolls when using SelText  (Read 3284 times)

bungayst

  • New Member
  • *
  • Posts: 15
RichMemo Scrolls when using SelText
« on: October 29, 2023, 02:03:03 am »
How do I stop this from happening? It's affecting the usability of the application.
When dragging text from a TreeView into a RichMemo the text scrolls/jumps and the user looses their place.

procedure TForm1.RichMemo1DragDrop(Sender, Source: TObject; X, Y: Integer);
var
  iNode  : String;
begin
  iNode := TTreeview(Source).Selected.Text; //Treeview is the Source.

// SelStart causes RichMemo to jump/scroll. Can this be stopped?
    RichMemo1.SelStart:=RichMemo1.CharAtPos(0,Y);
    RichMemo1.SelText:=iNode;
end;       


skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: RichMemo Scrolls when using SelText
« Reply #1 on: October 30, 2023, 03:35:59 am »
you can try to do something like that:
Code: Text  [Select][+][-]
  1. procedure TForm1.RichMemo1DragDrop(Sender, Source: TObject; X, Y: Integer);
  2. var
  3.   iNode  : String;
  4.   v : integer;
  5. begin
  6.   iNode := TTreeview(Source).Selected.Text; //Treeview is the Source.
  7.  
  8. // SelStart causes RichMemo to jump/scroll. Can this be stopped?
  9.     v := RichMemo1.VertScrollBar.Position;
  10.     RichMemo1.SelStart:=RichMemo1.CharAtPos(0,Y);
  11.     RichMemo1.SelText:=iNode;
  12.     RichMemo1.VertScrollBar.Position := v;
  13. end;    
  14.  

bungayst

  • New Member
  • *
  • Posts: 15
Re: RichMemo Scrolls when using SelText
« Reply #2 on: October 30, 2023, 09:47:00 pm »
I'm playing with this solution now. It doesn't throw any errors but it's not doing anything. Very strange.

The procedure now looks like this;

procedure TForm1.RichMemo1DragDrop(Sender, Source: TObject; X, Y: Integer);
var
  iNode  : String;
  v : Integer;

begin
  iNode := TTreeview(Source).Selected.Text; //Treeview is the Source.

  // Preserve the position of the Vertical Scrollbar
  v := RichMemo1.VertScrollBar.Position;
  // Set the starting position for the text to be inserted into the RichMemo
  RichMemo1.SelStart := RichMemo1.CharAtPos(0,Y);
  // Insert the text
  RichMemo1.SelText := iNode;
  // Reset the position of the Vertical Scrollbar
  RichMemo1.VertScrollBar.Position := v;
  // Put the values of v and RichMemo1.VertScrollBar.Position into two text boxes, lets see if they differ.
  Edit2.Text := IntToStr(v);
  Edit3.Text := IntToStr(RichMemo1.VertScrollBar.Position);
end; 

  And the result is that the values DO differ. The value of v, it seems, is not being stored in (accepted by?) RichMemo1.VertScrollBar.Position, and as a result the RichMemo keeps doing its thing. Most frustrating.
« Last Edit: October 30, 2023, 10:58:20 pm by bungayst »

 

TinyPortal © 2005-2018