我想一个 memo 两个button  一个edit 
memo中导入文本 然后点击一次 button  edit1.txt 自动添加一行memo
再次点击 添加memo下一行文本 如何实现
我的代码是
==
procedure TForm1.Button2Click(Sender: TObject);
begin
if opendialog1.Execute  then
memo1.Lines.LoadFromFile(opendialog1.FileName);
end;procedure TForm1.Button1Click(Sender: TObject);
var i,j:integer ;
k:string ;
begin
label1.Caption:='0';
k:=label1.Caption;
i:=0;
j:=memo1.Lines.Count ;
if i<>j then
edit1.Text:= memo1.Lines[i] ;
i:=i+1 ;
i:=strtoint(k);
label1.Caption:= k ;
=====貌似功能实现不了 请修正下 

解决方案 »

  1.   

    定义一个全局变量l;
    procedure TForm1.FormShow(Sender: TObject);//初始化变量l值为0
    begin
      l:=0;
    end;procedure TForm1.Button1Click(Sender: TObject);
    begin
       edit1.Text:=memo1.Lines.Strings[l];
       inc(l);
    end;
      

  2.   

    楼上的基本对,不过应该在调入文本文件之后清0:
    procedure TForm1.Button2Click(Sender: TObject); 
    begin 
    if opendialog1.Execute  then 
    begin
    memo1.Lines.LoadFromFile(opendialog1.FileName); 
    l:=0;
    end;
    endprocedure TForm1.Button1Click(Sender: TObject); 
    begin 
      edit1.Text:=memo1.Lines.Strings[l]; 
      inc(l); 
    end;
      

  3.   

    补充楼上的,呵呵
    也许该加个if l>=Memo1.Lines.Count then exit;