Forum > Beginners

Cursor position in TMemo like "gotoxy"

(1/2) > >>

pascal111:
Can I determine cursor position in TMemo control like "gotoxy" statement in C:


--- Code: C  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- main(){ gotoxy(1, 3);printf("This is 3rd line.\n"); }  

bobby100:
Did you try TMemo.CaretPos or TMemo.SelStart?

pascal111:
"memo1.CaretPos.SetLocation" has no effect at all.

"memo1.SelStart" changed "x" of the cursor, but has no effect on "memo1.Lines.Add".



--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit Unit1; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls; type   { TForm1 }   TForm1 = class(TForm)    Memo1: TMemo;    procedure FormCreate(Sender: TObject);    procedure Memo1Change(Sender: TObject);  private   public   end; var  Form1: TForm1; implementation {$R *.lfm} { TForm1 }  procedure TForm1.FormCreate(Sender: TObject);begin   memo1.SelStart:=4;  //memo1.CaretPos.SetLocation(1,3);  memo1.Lines.Add('Hello!');end; end.  

winni:
Hi!

First you have to add the text,
then you have to set the position.

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.Button3Click(Sender: TObject);beginmemo1.clear;memo1.Lines.add('Hello');memo1.Lines.add('World');memo1.Selstart := 7;memo1.SelLength:= 2;end; 
Winni

paweld:
the coordinate you want to set must exist
--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.Button1Click(Sender: TObject);var  p: TPoint;begin  //line 4, char 3  p := Point(2, 3);  if p.Y >= Memo1.Lines.Count then    p.Y := Memo1.Lines.Count - 1;  if p.X >= Length(Memo1.Lines[p.Y]) then    p.X := Length(Memo1.Lines[p.Y]) - 1;  Memo1.CaretPos := p;  Memo1.SetFocus;end;    

Navigation

[0] Message Index

[#] Next page

Go to full version