Jump to content

Line is the cursor of a Memo ?


Luciano França

Recommended Posts

In this link 

http://forums.unigui.com/index.php?/topic/5410-cursor-position-in-tunimemo/#comment-98286


I was able to know the column that is the cursor
but after a lot of searching and testing I didn't find anything that tells me how to know the line where the cursor is

I tried the code below but it doesn't work.

  JSAddListener('blur', 'function(){ajaxRequest(this, "_blur", ["cpos="+this.codeEditor.cursorPosition().line])}');

 

Link to comment
Share on other sites

3 hours ago, Luciano França said:

I have several situations where I need to know which line the cursor is on in VCL I use

In any case, keep in mind that the Web is not a VCL.
But despite this, there are some solutions on the forum, and I advise you to search the forum first and analyze the solutions!
For example, for UniSyntaxEdit, UniSyntaxEditEx. And I'm sure you'll find solutions for the analysis for the rest too.

 

Link to comment
Share on other sites

8 hours ago, Sherzod said:

In any case, keep in mind that the Web is not a VCL.
But despite this, there are some solutions on the forum, and I advise you to search the forum first and analyze the solutions!
For example, for UniSyntaxEdit, UniSyntaxEditEx. And I'm sure you'll find solutions for the analysis for the rest too.

 

 

I believe that the colleague does not understand what I need

These posts you passed I had already analyzed and nothing does what I need

I need to know which line the cursor is on
as I had already mentioned in VCL I achieve this using  "Lin := Memo1.CaretPos.y;"

A possible dirty solution I just created

procedure TMainForm.UniFormCreate(Sender: TObject);
begin
  with UniMemo1.JSInterface do
    JSAddListener('blur', 'function(){ajaxRequest(this, "_blur", ["cpos="+this.inputEl.dom.selectionStart])}');

end;

procedure TMainForm.UniMemo1AjaxEvent(Sender: TComponent; EventName: string;
  Params: TUniStrings);
begin
  if EventName = '_blur' then
    (Sender as TUniMemo).CustomAttribs.Values['cpos'] := Params.Values['cpos'];

end;

Function F_LineCursorMemo(uniMemo: TUniMemo): Integer;
var i, aSelStart: Longint;
 Texto: String;
begin
 uniMemo.Setfocus;

 Texto := StringReplace(uniMemo.Text, #13, '', [rfReplaceAll]);
 aSelStart := StrtoIntDef(uniMemo.CustomAttribs.Values['cpos'], 0);

 Result := 1;
 for i := 1 to aSelStart do Begin
  if (Texto[i] = #10) Then
   inc(Result);
 End;

end;

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...