Delphi文本文件的写操作
最近我用Delphi写了个程序,需要将用户信息写入文件,因此在网上查了下
Delphi有关文本文件的操作,经整理后,我将其封装成了一个函数,
Delphi有关文本文件的操作,经整理后,我将其封装成了一个函数,
以方便以后的使用,访函数代码如下:
//将帐号信息写入文本文件函数 procedure TForm1.WriteUserToText(user:String; pass:String); var txt:TextFile; begin //先判断一下文件是否存在, 不存在时就创建它 if not FileExists('C:\p.txt') then begin Assignfile(txt,'c:\p.txt'); //指定文件路径 rewrite(txt); //创建并打开一个新文件(或覆盖原有文件) Closefile(txt); //关闭打开的文件 end; AssignFile(txt,'C:\p.txt'); Append(txt); //以追加的方式打开文件,指针到尾 Writeln(txt,user+'--->'+pass); //写文件 CloseFile(txt); //关闭打开的文件 end; /////////////////////////////////////////////////////////////
![](http://r.qzone.qq.com/cgi-bin/cgi_get_user_pic?openid=00000000000000000000000005492D01&pic=1.jpg&key=14c00103d64a28b46e3a7211892ffbee)
探索代码的奥秘,享受技术的乐趣-_-!...