delphi7 读写txt

 

procedure TForm1.newClick(Sender: TObject);
var
f:textfile;
filename:string;
begin
  filename:='a.txt';
  if not fileexists(filename) then
  begin
    assignfile(f,filename);
    rewrite(f);
    closefile(f);
    e.Text:='ok';
  end;

end;

procedure TForm1.Button2Click(Sender: TObject);
var
f:textfile;
filename:string;
begin
  filename:='a.txt';
  assignfile(f,filename);
  rewrite(f);
  writeln(f,'aa');
  closefile(f);
end;

procedure TForm1.Button1Click(Sender: TObject);
var
f:textfile;
filename:string;
str:string;
begin
  filename:='a.txt';
  assignfile(f,filename);
  reset(f);
  readln(f,str);
  closefile(f);
  e.Text:=str;
end;

你可能感兴趣的:(Delphi技术)