如何解决在delphi中取消文件对话框时如何防止I / O 6
在我的程序中,我有一个openfile对话和一个savefile对话。每当我在这些对话框中按取消时,都会收到I / O错误6。如何删除此错误?
procedure TForm1.Open1Click(Sender: TObject);
var
s: string;
// Declares a file type for storing lines of text
t: TextFile;
begin
mmo1.Lines.Clear;
// Set up the starting directory to be the current one
dlgOpen1.InitialDir := 'Libraries\Documents';
// Opens the file Dialogue
dlgOpen1.Execute;
// Assigns contents of the chosen
AssignFile(t,dlgOpen1.FileName);
// Opens a file given by FileHandle for read,write or read and write access
// Must use AssignFile to assign a file to the FileHandle before using Reset
Reset(t);
// The While keyword starts a control loop that is executed as long as the
// - Expression is satisfied (returns True)
// The Eof function returns true if the file given by FileHandle is at the end
// All this essentialy adds the contents of the text file,line by line until
// - there is no more text to be added
while not Eof(t) do
begin
// Reads a complete line of data from a text file
Readln(t,s);
mmo1.Lines.Add(s);
end;
CloseFile(t);
end;
解决方法
您必须这样做:
if dlgOpen1.Execute then
begin
// ...all your file management here
end;
dlgOpen1.execute如果用户取消对话框,则返回false。
,您必须检查dlgOpen1.Execute
的返回值:
if not dlgOpen1.Execute then
Exit;
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。