本帖最后由 lcop2011 于 2011-09-22 19:24:50 编辑

解决方案 »

  1.   

    我不是答了你关于memo同样内容的贴了吗?怎么还没解决?
      

  2.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, ComCtrls;type
      TForm1 = class(TForm)
        RichEdit1: TRichEdit;
        Edit1: TEdit;
        procedure RichEdit1KeyPress(Sender: TObject; var Key: Char);
        procedure FormCreate(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
    begin
      richedit1.Text:='';
    end;procedure TForm1.RichEdit1KeyPress(Sender: TObject; var Key: Char);
    var i,k :integer;
        s,ls:string;
    begin
      if key=#13 then
      begin
        key:=#0;
        if richedit1.Lines.Count<1 then exit;
        if richedit1.Lines.Count>0 then i:=richedit1.Lines.Count-1;
        s:=richedit1.Lines.Strings[i];
        k:=pos('=',s);
        ls:=copy(s,1,k);
        richedit1.Lines.Add(ls);
        edit1.Text:=inttostr(richedit1.Lines.Count);
        richedit1.SelStart:=length(richedit1.Text);
        richedit1.SelLength:=0;
        richedit1.SetFocus;
      end;
    end;end.
      

  3.   

    肯定是两行,你并没有限制回车的执行,加一句  if Key = #13 then Key := #0;
      

  4.   

    我比较菜,delphi似懂非懂,主要还是基础太差,研究下楼上两位的办法
      

  5.   

    就一个判断ok了:
    procedure TForm1.RichEdit1KeyPress(Sender: TObject; var Key: Char);
    var i,k :integer;
        s,ls:string;
    begin
      if key=#13 then
      begin
        key:=#0;
        if richedit1.Lines.Count<1 then exit;
        i:=richedit1.Lines.Count-1;
        s:=richedit1.Lines.Strings[i];
        k:=pos('=',s);
        ls:=copy(s,1,k);
        richedit1.Lines.Add(ls);
        edit1.Text:=inttostr(richedit1.Lines.Count);
        richedit1.SelStart:=length(richedit1.Text);
        richedit1.SelLength:=0;
        richedit1.SetFocus;
      end;
    end;
      

  6.   

    给你解析下:
    procedure TForm1.RichEdit1KeyPress(Sender: TObject; var Key: Char);
    var i,k :integer;
        s,ls:string;
    begin
      if key=#13 then//如果回车键被按下了
      begin
        key:=#0;//把回车的动作消掉
        if richedit1.Lines.Count<1 then exit;//如果richedit1没内容,不往下执行
        i:=richedit1.Lines.Count-1;//取最后一行的索引值
        s:=richedit1.Lines.Strings[i];//取最后一行的字符
        k:=pos('=',s);//求等号在字符串的位置
        ls:=copy(s,1,k);//从字符串第一个开始、复制到(包括)等号
        richedit1.Lines.Add(ls);//将刚复制的字符串添加进richedit1内
        edit1.Text:=inttostr(richedit1.Lines.Count);//在edit1中显示richedit1的行数
        richedit1.SelStart:=length(richedit1.Text);//选择的起始位
        richedit1.SelLength:=0;//选择字符的个数
        richedit1.SetFocus;//让richedit1获得焦点
      end;
    end;
      

  7.   

    哎,一楼的在memo帖子里面就用到key:=#0这个了,其实只要用了if Key = #13 then Key := #0;这句,光标就自动定位在"="号右侧了,真郁闷,还是基础太差的原因,得加油了。
    谢谢楼上两位,结贴,散发。另外,麻烦你们谁去点击下这个,帖子没用顶,结贴不了。谢谢
    http://topic.csdn.net/u/20110909/01/7bda7a33-2b9e-4af9-a794-7a8c751ce046.html