码迷,mamicode.com
首页 > 其他好文 > 详细

打开并锁定一个文件

时间:2016-09-26 19:33:21      阅读:89      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!