// 写入文本文件的函数 Text:字符串 FileName1:文件名
procedure TFrm1.WriteTextFileContents(text:string;fileName1:string);
var
myfile:textFile;
begin
AssignFile(myFile,fileName1);
rewrite(myFile); //覆盖或创建新的try
writeln(myfile,text);
finally
closeFile(myFile);
end; //try
end;//调用
str:='1'+#13+'100'
showMessage(str); //可以显示出是换行了
frm1.WriteTextFileContents(str,'m.txt'); // m.txt文件中显示的是方块// 从m.txt中读取
function TFrm1.ReadTextFileContents(filename1:string):string;
var
myfile:textFile;
s:string;
begin
AssignFile(myFile,fileName1);
if FileExists(fileName1) then
reset(myFile)
else
raise Exception.Create(fileName1+'文件不存在');try
while not eof(myFile) do
begin
readln(myfile,s);
result:=result+s;
end; //while
finally
closeFile(myFile);
end; //try
showMessage(result); // 是连在一起的
end;
// 为什么向m.txt中写入的时候含有#13也就是说有回车了
可是读取的时候不能读出来换行了我是想要的结果是是:
比如你写入文件文件是 'first'+#13+'second' //要一次性写入,而不用写一行first再写second
那么我读出来的也是 'first'+#13+'second' ,而不是连在一起的是不是Writeln,或Readln有错啊?
谢谢
procedure TFrm1.WriteTextFileContents(text:string;fileName1:string);
var
myfile:textFile;
begin
AssignFile(myFile,fileName1);
rewrite(myFile); //覆盖或创建新的try
writeln(myfile,text);
finally
closeFile(myFile);
end; //try
end;//调用
str:='1'+#13+'100'
showMessage(str); //可以显示出是换行了
frm1.WriteTextFileContents(str,'m.txt'); // m.txt文件中显示的是方块// 从m.txt中读取
function TFrm1.ReadTextFileContents(filename1:string):string;
var
myfile:textFile;
s:string;
begin
AssignFile(myFile,fileName1);
if FileExists(fileName1) then
reset(myFile)
else
raise Exception.Create(fileName1+'文件不存在');try
while not eof(myFile) do
begin
readln(myfile,s);
result:=result+s;
end; //while
finally
closeFile(myFile);
end; //try
showMessage(result); // 是连在一起的
end;
// 为什么向m.txt中写入的时候含有#13也就是说有回车了
可是读取的时候不能读出来换行了我是想要的结果是是:
比如你写入文件文件是 'first'+#13+'second' //要一次性写入,而不用写一行first再写second
那么我读出来的也是 'first'+#13+'second' ,而不是连在一起的是不是Writeln,或Readln有错啊?
谢谢
解决方案 »
- 如何自定义一个多级的Class类
- Intraweb应用程序在IIS 7.5(Windows 7 64位)发布的几点设置
- SQL如何实现带进度条的数据库备份和还原
- DELPHI初学者请教个问题``
- 一个菜鸟问题:delphi 7中打印报表的Qreport在哪里?怎么添加啊?
- 关于tdbchart的初级学习
- 101 分问:关于COM事件,D5、6开发指南的一点疑问!
- 多层应用,请低手指教!!!
- 这个语句哪里错了呢 送10分
- 怎样把JAVA转成delphi的代码(CRC16-CCITT的校验值,遵循大端排序方式)
- 问个PASCAL语法问题,with do 是什么作用呀?书上没有解释呢?
- 关于 PageControl !!! 在 PageControl中创建了窗体,但是有一点很奇怪..... 进来慢慢说
#13是回车,#10是换行
写入的时候应该是 'first'+#13+#10+'second' ,txt文件中就不会显示方块了
#13是回车,#10是换行==还是有方块的,如果放到不是.txt的文件的话,就可以换行是我自己一个地方搞错了,现在解决了
同谢