Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   OOP (https://www.clubdelphi.com/foros/forumdisplay.php?f=5)
-   -   Tmemo Index(saber en que linea estoy) (https://www.clubdelphi.com/foros/showthread.php?t=5959)

Descendents 12-12-2003 12:23:28

Tmemo Index(saber en que linea estoy)
 
¿Es posible saber en que linea me encuentro al hacerle un click dentro de un memo?

Tengo un boton para borrar lines de un memo.

hago lo siguiente:

Memarx.Lines.Delete(n);

Necesito saber n. Como puedo saber en que linea estoy?

Tambien. ¿Es posible seleccionar toda la linea desde un memo?

Cuando le doy click a la linea 1 se me seleccione en azul toda la linea.

Un saludo
Gracias.

roman 12-12-2003 18:38:10

Para hallar el número de línea (basado en 0) en donde se encuantra el cursor:
Código:

Line := SendMessage(Memo1.Handle, EM_LINEFROMCHAR, -1, 0);
Una vez que tienes la línea, para seleccionarla necesitas saber el primer y último caracter (su índice basado en el comienzo de todo el texto del Memo):
Código:

StartChar := SendMessage(Memo1.Handle, EM_LINEINDEX, Line, 0);
EndChar := SendMessage(Memo1.Handle, EM_LINEINDEX, Line + 1, 0);

y usar las propiedades SelStart y SelLength del Memo.

Todo junto lo podrías poner en el evento OnClick del Memo:

Código:

procedure TForm1.Memo1Click(Sender: TObject);
var
  Line: Integer;
  StartChar, EndChar: Integer;

begin
  Line := SendMessage(Memo1.Handle, EM_LINEFROMCHAR, -1, 0);
  StartChar := SendMessage(Memo1.Handle, EM_LINEINDEX, Line, 0);
  EndChar := SendMessage(Memo1.Handle, EM_LINEINDEX, Line + 1, 0);

  Memo1.SelStart := StartChar;
  Memo1.SelLength := EndChar - StartChar;
end;


// Saludos

Descendents 12-12-2003 19:51:48

Muchas gracias Roman

Perfecto
Un saludo


La franja horaria es GMT +2. Ahora son las 21:40:41.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi