Recent

Author Topic: SOLVED How to move the caret in a TMemo  (Read 3737 times)

JLWest

  • Hero Member
  • *****
  • Posts: 1293
SOLVED How to move the caret in a TMemo
« on: February 28, 2019, 11:13:45 pm »
I copied this from the form and trying to get it work.

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var
  3.   line: integer;
  4. begin
  5.   line := Memo1.Perform(EM_LINEFROMCHAR, Memo1.SelStart, 0);
  6. end;

I get the following error:
unit1.pas(158,30) Error: Identifier not found "EM_LINEINDEX".
Do I need something added to the use clause
 
« Last Edit: February 28, 2019, 11:54:20 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

jamie

  • Hero Member
  • *****
  • Posts: 6091
Re: How to move the caret in a TMemo
« Reply #1 on: February 28, 2019, 11:27:15 pm »
Those are windows defines and needs the Windows unit in  the USES list

You use the SendMessage(Memo1.handle, EM_...….)

The SelectStart and SelectLength will also place your caret
The only true wisdom is knowing you know nothing

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Re: How to move the caret in a TMemo
« Reply #2 on: February 28, 2019, 11:42:41 pm »
Sorry I don't understand .

Memo1.SelectStart(0); gives an error.

Trying to move to the first line or position in Memo1.

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

jamie

  • Hero Member
  • *****
  • Posts: 6091
Re: SOLVED How to move the caret in a TMemo
« Reply #3 on: March 01, 2019, 02:15:23 am »
memo.SelStart := ?

Memo.SelLength := 0; or make it a length.

keep in mind the memo is one long string.

if lines wrap in the memo, the line count changes.


The only true wisdom is knowing you know nothing

furious programming

  • Hero Member
  • *****
  • Posts: 853
Re: SOLVED How to move the caret in a TMemo
« Reply #4 on: March 01, 2019, 02:26:41 am »
The TMemo.CaretPos property is used to read the cursor position and its setting:

Code: Pascal  [Select][+][-]
  1. Memo.CaretPos := TPoint.Create(10, 5);  // tenth character on the sixth line
« Last Edit: March 01, 2019, 02:28:54 am by furious programming »
Lazarus 3.2 with FPC 3.2.2, Windows 10 — all 64-bit

Working solo on an acrade, action/adventure game in retro style (pixelart), programming the engine and shell from scratch, using Free Pascal and SDL. Release planned in 2026.

 

TinyPortal © 2005-2018