新手请教为何 API函数编程 速度太慢
如题,以下是代码:unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
hFile: THandle;
iLen: LongWord;
Buffer: AnsiString;
SizeDisk: int64;
FreeSize: int64;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
FreeSize := DiskFree(4); //获取D:可用空间
Buffer := '00000000'; //一个字节的0
hFile := CreateFile('D:\Data.dat',
GENERIC_WRITE,
0,
Nil,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL ,
0);
if (hFile = INVALID_HANDLE_VALUE) then
begin
MessageBox(GetActiveWindow(),'创建文件失败!',Nil,MB_OK or MB_ICONERROR);
Exit;
end;
SetFilePointer(hFile,1,NIL,FILE_BEGIN);
WrITeFile( hFile, Buffer[1], Length(Buffer), iLen, Nil);
while FreeSize>0 do
begin
FreeSize:=FreeSize-1;
SetFilePointer(hFile,1,NIL,FILE_CURRENT);
WrITeFile( hFile, Buffer[1], Length(Buffer), iLen, Nil);
end;
CloseHandle(hFile);
end;
end.
[ 本帖最后由 tomsen1968 于 2010-4-4 12:01 编辑 ]