Delphi中Memo组件的光标定位 罗起 
  作为一个与VisualBasic相类似,但功能更强大的可
视化程序开发工具,Delphi同样提供了大量的简单便捷的
控制组件,通过这些组件,程序设计者可以设计出规范美
观的界面。并且规范化使用者的输入内容。其中,Delphi
提供的编辑组件中的Memo组件的功能是非常丰富的。它可
以完成对文字的编辑、修改、文件的调入和存储文件等功
能,但是与一般的字处理软件相比,它并未提供编辑时对
光标位置、所在行及所在列的信息,这不能说不是一个缺
憾。其实,通过很简单的几行程序就可以实现这一要求:  先在Form上放置三个Label组件,并在程序代码的前
面声明下面这三个变量为整型数,即:  VarLpos,Cpos,Linelength:integer;  其中Lpos是行的值(按照Memo的规定,第一行为0)
,Cpos是字符的位置,LineLength是当前行的字符总个数
。  然后,再将下面的七行程序代码分别加入Memo1的OnM
ouseDown和OnKeyDown的事件代码处即可。  Lops:ΚSendMessage(memol.Handle,EM—LINEFR
OMCHAR,Memol.SelStart,0);  Cpos:ΚSendMessage(meno1.Handle,EM—LINEIN
DEX,Lpos,0);  LineLength:ΚSendMessage(memol.handle,EM—
LINELENGTH,Cpos,0);  Cpos:ΚMemol.SelStart-CPos;  Labell.caption:Κinttostr(lpos);  Label2.caption:Κinttostr(cpos);  Label3.caption:Κinttostr(linelength);  这样,执行程序后,随着在Memo组件中的编辑操作,
Label1、Label2和Label3就将显示出相对应的当前行值、
字符位置与当前行的字符总个数了至于读写ini文件,就更加简单了:
使用TIniFile类绝对没错的!
var myini : TIniFile ;myini := TIniFile.Create('d:\abc.ini');
try
//写入整型值:
   myini.WriteInteger('父类名称','子类名称',缺省值);
//读出整型值:
   myini.ReadInteger('父类名称','子类名称',缺省值);
  //其它类似即可
finally
  myini.Free;
end; 

解决方案 »

  1.   

    TMemo的属性CaretPos不是可以指示光标位置吗?Good Luck!
      

  2.   

    这是他的说明
    Use CaretPos to determine the coordinates of the cursor. CaretPos indicates the X and Y position (in terms of lines and characters) relative to the client origin of the memo.To determine the position of the caret in terms of characters of text only (rather than X/Y location), use the SelStart property.