声明变量
var
f:TextFile;系统提示如下信息:
[Pascal Error] Unit2.pas(1): Unable to invoke Code Completion due to errors in source code请高手指点如何使用TextFile
var
f:TextFile;系统提示如下信息:
[Pascal Error] Unit2.pas(1): Unable to invoke Code Completion due to errors in source code请高手指点如何使用TextFile
procedure TForm1.Button1Click(Sender: TObject);
var MyFile:TextFile;
s:string;
begin
try
AssignFile(MyFile,'d:\a.txt');
Reset(MyFile);
Memo1.Clear;
while not Eof(MyFile) do
begin
ReadLn(MyFile,s);
Memo1.Lines.Add(s);
end; finally
CloseFile(MyFile);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var MyFile:TextFile;
s:string;
begin
try
AssignFile(MyFile,'d:\a.txt');
Append(MyFile); //或用ReWrite(MyFile),append是不覆盖原文,原文不存在将出错,Rewrite是覆盖原文,文件不存在将创建,
s:='write textfile';
WriteLn(MyFile,s);
finally
CloseFile(MyFile);
end;
end;