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
时间: 2024-12-05 06:31:03