超难问题!!!!!!!! 如何判断   edit 控件的 光标 在第几个字符上???????????????????? 急!!!!!!!!!!!!

解决方案 »

  1.   

    function getPosition:TPosition;var  row,Col:longint;  CBLines:longint;  str:WideString;begin//该消息取得光标所在的行,  row:= SendMessage(Handle,EM_LINEFROMCHAR,SelStart,0);  //该消息取得光标所在行开始的位置,位置从第一行的0开始计数,  //每过一个字符增加1,  CBLines:=SendMessage(Handle,EM_LINEINDEX,row,0);  //得到光标的所在行的所在列  Col:=SelStart-CBLines;  //为了解决中文的问题,需要用宽字符型来取得光标所在行  //,行中光标所在列之前的字符串,这样可以解决中文列数的确定问题.  str:=Copy(Lines[row],1,col);  col:=Length(Str)+1;  result.row:=row+1;  result.col:=col;end;参考上面代码
      

  2.   

    调用API函数
    光标获取
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, Buttons,SHELLAPI;type
      TForm1 = class(TForm)
        Memo1: TMemo;
        Label1: TLabel;
        Label2: TLabel;
        Button1: TButton;
        Label3: TLabel;
        Label4: TLabel;
       
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
    var
    LineNum:longint;
    CharsBeforeLine:longint;
    begin
          LineNum := SendMessage(Memo1.Handle,EM_LINEFROMCHAR,
          Memo1.SelStart,0);
          CharsBeforeLine:=SendMessage(Memo1.Handle,EM_LINEINDEX,
          LineNum,0);
          Label1.Caption:='Line: '+IntToStr(LineNum + 1);
          Label2.Caption:='Position: '+IntToStr((Memo1.SelStart -
          CharsBeforeLine)+1);
    end;
    end.
      

  3.   

    调用函数, 支持naner_china(naner)的方法。