以下程序的目的是:单击按钮Button1,如果在F盘根目录下不存在文件log.txt,则创建该文件,并写一行字符串Hello,如已存在,则直接将该字符串写入文件中。
现在执行时,如果文件已经存在,则运行正常;如果不存在,则
运行到(**)处发生异常:I/O error 32
请哪位高手帮帮忙。不胜感激!
object Form1: TForm1
Left = 192
Top = 112
Width = 696
Height = 480
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -13
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 120
TextHeight = 16
object Button1: TButton
Left = 240
Top = 192
Width = 75
Height = 25
Caption = 'Button1'
TabOrder = 0
OnClick = Button1Click
end
end
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
FileName:TextFile;
begin
if not FileExists('f:\log.txt') then
if FileCreate('f:\log.txt')=-1 then
begin
ShowMessage('Cannot create the log file!');
end;
AssignFile(FileName,'f:\log.txt');
Append(FileName); (**)
Writeln(FileName,'Hello');
Flush(FileName);
CloseFile(FileName);
end;end.
现在执行时,如果文件已经存在,则运行正常;如果不存在,则
运行到(**)处发生异常:I/O error 32
请哪位高手帮帮忙。不胜感激!
object Form1: TForm1
Left = 192
Top = 112
Width = 696
Height = 480
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -13
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 120
TextHeight = 16
object Button1: TButton
Left = 240
Top = 192
Width = 75
Height = 25
Caption = 'Button1'
TabOrder = 0
OnClick = Button1Click
end
end
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
FileName:TextFile;
begin
if not FileExists('f:\log.txt') then
if FileCreate('f:\log.txt')=-1 then
begin
ShowMessage('Cannot create the log file!');
end;
AssignFile(FileName,'f:\log.txt');
Append(FileName); (**)
Writeln(FileName,'Hello');
Flush(FileName);
CloseFile(FileName);
end;end.
解决方案 »
- delphi Webbrowser控件 复制与粘贴问题
- delphi嵌套一个webbrowser 如何去掉它的边框
- 关于GLScene控件的帮助文档 请各位大哥帮忙提供!
- 关于dblookupcombobox的疑问
- 哪位大侠能帖一个TreeView1控件的使用例子吗?
- 我改了一个vcl的pas,但改了后不知道怎样编译,请问怎样找到这个pas的单元文件
- 如何把数据库软件变得更简洁
- 想进军Delphi,希望过来人能指点方向(目前已用java一年多)
- 点击按钮,将删除MS-SQL SERVER6.5上的一个别名为AA的数据库。该怎么做?点击按钮,将删除MS-SQL SERVER6.5上的一个别名为AA的数据库的一
- 分来了!
- 关于远程ERP系统如何实现?
- rave报表编辑器的工具条上那些drawing 之类的按钮不见了
var
FileHandle: Integer;FileHandle := FileCreate(SaveDialog1.FileName);
FileWrite(FileHandle,'hello', Length('hello'));
FileClose(FileHandle);
var
FileName:TextFile;
begin
if not FileExists('f:\log.txt') then
begin
AssignFile(FileName,'f:\log.txt');
Rewrite(FileName);
if not FileExists('f:\log.txt') then
begin
ShowMessage('Cannot create the log file!');
end;
CloseFile(FileName);
end
else
begin
AssignFile(FileName,'f:\log.txt');
Append(FileName);
Writeln(FileName,'Hello');
Flush(FileName);
CloseFile(FileName);
end;
end;