首页 > 其他 > 详细

打开并锁定一个文件

时间:2016-09-26 19:32:50      阅读:160      评论:0      收藏:0      [点我收藏+]
var
  aHandle     : THandle;
  aFileSize   : Integer;
  aFileName   : String;

procedure TForm1.Button3Click(Sender: TObject);
begin
    aFileName    := C:\101\Java_new.pdf;
    aHandle      := CreateFile(PChar(aFileName),GENERIC_READ, 0, nil, OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0); // get the handle of the file

    aFileSize   := GetFileSize(aHandle,nil); //get the file size for use in the  lockfile function
    Win32Check(LockFile(aHandle,0,0,aFileSize,0)); //lock the file
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
    Win32Check(UnlockFile(aHandle,0,0,aFileSize,0));//unlock the file
    CloseHandle(aHandle);//Close the handle of the file.
end;

 

http://stackoverflow.com/questions/1916084/how-do-i-get-the-handle-for-locking-a-file-in-delphi

打开并锁定一个文件

原文:http://www.cnblogs.com/findumars/p/5910100.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!