代码改变世界

[delphi函数]FileCreate 建立新文件

2009-12-04 22:18  HYrz的菜园子  阅读(870)  评论(0编辑  收藏  举报

//建立新文件 FileCreate
var
FileName: string;
i: Integer;
begin
FileName := 'c:\temp\test.dat';
i := FileCreate(FileName);

if i>0 then
    ShowMessage('新文件的句柄是: ' + IntToStr(i))
else
    ShowMessage('创建失败!');
end;

=================

function FileCreate(const FileName: string): Integer;
{$IFDEF MSWINDOWS}
begin
Result := Integer(CreateFile(PChar(FileName), GENERIC_READ or GENERIC_WRITE,
    0, nil, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0));
end;
{$ENDIF}
{$IFDEF LINUX}
begin
Result := FileCreate(FileName, FileAccessRights);
end;
{$ENDIF}