Board index » delphi » Add string in cursor position

Add string in cursor position

Hello,

I want to insert a string in the cursor position of TMemo component

How can i determine the current cursor position (line numer and character
number) in TMemo component ?

Nir.

 

Re:Add string in cursor position


In article <4f39ca$...@news.NetVision.net.il>, n...@netvision.net.il
says...

Quote

>Hello,

>I want to insert a string in the cursor position of TMemo component

>How can i determine the current cursor position (line numer and character
>number) in TMemo component ?

>Nir.

Hi!

If you want to insert a text at the current cursor position, you can use
the EM_ReplaceSel Message.

SENDMESSAGE (EditField.HANDLE, EM_REPLACESEL, 0, LONGINT(@szText))

In this example EditField is your Edit-Component. szText is a var which
contains which you want to insert. szText must be a zero-terminated string
(C-String). You can find more information in the API-help.

Bye and Good Luck

Andreas

--
=============================================
helicon software development - Andreas Prucha
Baden/Vienna, Austria - heli...@helicon.co.at
=============================================

Re:Add string in cursor position


This should work

Memo1.SetSelTextBuf('HELLO');

Ivan

Re:Add string in cursor position


Quote
n...@netvision.net.il (Nir Sofer) wrote:
>Hello,
>I want to insert a string in the cursor position of TMemo component
>How can i determine the current cursor position (line numer and character
>number) in TMemo component ?
>Nir.

Why not use:

Memo1.SelText := String;

Re:Add string in cursor position


In article <4f39ca$...@news.NetVision.net.il>, n...@netvision.net.il (Nir Sofer) says:

Quote

>Hello,

>I want to insert a string in the cursor position of TMemo component

>How can i determine the current cursor position (line numer and character
>number) in TMemo component ?

>Nir.

Hi Nir,

this will insert text in the cursor position

Memo.SetSelTextBuf('Buffer');

for more try Delphi's help on SetSelTextBuf

to answer your second part of your question

try this to set and get cursor position

unit Cursor;

interface

uses
  SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  Forms, Dialogs, StdCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    Panel1: TPanel;
    ButtonSetCursor: TButton;
    ButtonGetCursor: TButton;
    procedure ButtonGetCursorClick(Sender: TObject);
    procedure ButtonSetCursorClick(Sender: TObject);
    procedure GetMemoLineCol(Memo:TMemo;
                             var MemoLine, MemoCol: Integer);
    procedure SetMemoLineCol(Memo:TMemo;
                             MemoLine, MemoCol: Integer);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.ButtonGetCursorClick(Sender: TObject);
var
   MemoLine, MemoCol: Integer;
begin
     {Display the memo's cursor position}
     GetMemoLineCol(Memo1, MemoLine, MemoCol);
     Panel1.Caption := 'Line: ' + IntToStr(MemoLine+1) +
                       ' Col: ' + IntToStr(MemoCol);
end;

procedure TForm1.ButtonSetCursorClick(Sender: TObject);
begin
     {Move The cursor to line 3, column 5}
     ActiveControl := Memo1;
     SetMemoLineCol(Memo1, 2, 5);
end;

procedure TForm1.GetMemoLineCol(Memo:TMemo;
                             var MemoLine, MemoCol: Integer);
begin
     with Memo do
     begin
          MemoLine := SendMessage(Handle, EM_LINEFROMCHAR,
                                  SelStart,0);
          MemoCol := SelStart - SendMessage(Handle, EM_LINEINDEX,
                                  MemoLine,0)+1;
          Memo.SetFocus;
     end;
end;
procedure TForm1.SetMemoLineCol(Memo:TMemo;
                             MemoLine, MemoCol: Integer);
begin
     Memo.SelStart := SendMessage(Memo1.Handle, EM_LINEINDEX,
                                  MemoLine,0)+MemoCol-1;
     Memo.SetFocus;
end;

end.

Re:Add string in cursor position


Quote
 heli...@helicon.co.at (helicon) wrote:
>In article <4f39ca$...@news.NetVision.net.il>, n...@netvision.net.il
>says...

>>Hello,

>>I want to insert a string in the cursor position of TMemo component

>>How can i determine the current cursor position (line numer and character
>>number) in TMemo component ?

>>Nir.

I found a real easy way to do this.  Copy your text into the clipboard
and then paste from it into your memo field.  The paste will always
paste at the point where the cursor is sitting.

Re:Add string in cursor position


In article <4fb58q$...@news1.usa.pipeline.com>,
   c_cou...@usa.pipeline.com (Alexander Rheaume) wrote:
Quote
>n...@netvision.net.il (Nir Sofer) wrote:

>>Hello,

>>I want to insert a string in the cursor position of TMemo component

>>How can i determine the current cursor position (line numer and character
>>number) in TMemo component ?

>>Nir.

>Why not use:

>Memo1.SelText := String;

This will overwrite the currently selected text. If you want to insert the
string at the current cursor position (Memo1.SelStart), you must set
Memo.SelLength to 0 first.

Regards,
Matthias

----
Matthias Romppel                   email: mrom...@gwdg.de
Institute for Psychology
Gosslerstr. 14
37073 Goettingen
Germany

Other Threads