1、

2、Delphi (Windows API 文件尾部添加)

function LogFile(_str :string) :integer;
var hFile :THandle;
strFileName :string;
dwWritten :DWORD;
lb :LongBool;
begin
Result := ;
strFileName := ParamStr()+'.'+FormatDateTime('yyyymmdd', now)+'.log';
hFile := CreateFile(PChar(strFileName), GENERIC_WRITE, FILE_SHARE_READ, , CREATE_NEW, , );
if (hFile = INVALID_HANDLE_VALUE) then
begin
Result := GetLastError;
Exit;
end;
lb := Windows.SetEndOfFile(hFile);
if (not lb) then
begin
Result := GetLastError;
CloseHandle(hFile);
Exit;
end;
dwWritten := ;
lb := Windows.WriteFile(hFile, _str[], Length(_str), dwWritten, nil);
if (not lb) then
begin
Result := GetLastError;
CloseHandle(hFile);
Exit;
end;
CloseHandle(hFile);
end;

3、

05-11 17:08
查看更多