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, , nil, OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,); // get the handle of the file aFileSize := GetFileSize(aHandle,nil); //get the file size for use in the lockfile function
Win32Check(LockFile(aHandle,,,aFileSize,)); //lock the file
end; procedure TForm1.Button4Click(Sender: TObject);
begin
Win32Check(UnlockFile(aHandle,,,aFileSize,));//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

打开并锁定一个文件(使用LockFile API函数)的更多相关文章

  1. C#打开或者创建一个文件,然后向其末尾写入数据的方法

    原文:C#打开或者创建一个文件,然后向其末尾写入数据的方法             FileStream fs = new FileStream(@"d:\timetick.txt" ...

  2. open, creat - 用来 打开和创建 一个 文件或设备

    SYNOPSIS 总览 #includ e <sys/types.h> #include <sys/stat.h> #include <fcntl.h> int o ...

  3. Windows文件操作的API函数[转载]

    在VC中,大多数情况对文件的操作都使用系统提供的 API 函数,但有的函数我们不是很熟悉,以下提供一些文件操作 API 函数介绍: 一般文件操作 API CreateFile 打开文件 要对文件进行读 ...

  4. VC++打开对话框选择一个文件夹路径 BROWSEINFO结构

    typedef struct _browseinfoW { HWND hwndOwner; PCIDLIST_ABSOLUTE pidlRoot; LPWSTR pszDisplayName; // ...

  5. python一个文件里面多个函数同时执行(多进程的方法,并发)

    #coding=utf-8 import timefrom selenium import webdriverimport threading def fun1(a): print a def fun ...

  6. 与众不同 windows phone (38) - 8.0 关联启动: 使用外部程序打开一个文件或URI, 关联指定的文件类型或协议

    [源码下载] 与众不同 windows phone (38) - 8.0 关联启动: 使用外部程序打开一个文件或URI, 关联指定的文件类型或协议 作者:webabcd 介绍与众不同 windows ...

  7. 程序4-5 打开一个文件,然后unlink

    //http://blog.chinaunix.net/uid-24549279-id-71355.html /* ========================================== ...

  8. PHP文件操作 之读取一个文件(以二进制只读的方式打开)

    最近应用了文件的读取,顺便复习一下! //读取一个文件 $f = fopen($filename,'rb'); $f: 表示返回的一个资源句柄 $filename:要打开的文件路径 rb:参数,表示只 ...

  9. 重新想象 Windows 8 Store Apps (33) - 关联启动: 使用外部程序打开一个文件或uri, 关联指定的文件类型或协议

    原文:重新想象 Windows 8 Store Apps (33) - 关联启动: 使用外部程序打开一个文件或uri, 关联指定的文件类型或协议 [源码下载] 重新想象 Windows 8 Store ...

随机推荐

  1. 关于hexo的SEO的好文章

    1.hexo高阶教程:想让你的博客被更多的人在搜索引擎中搜到吗? 2.Hexo Seo优化让你的博客在google搜索排名第一 3.hexo 博客 seo 优化 4.HEXO SEO 高级优化 5.H ...

  2. 【20.35%】【codeforces 651D】Image Preview

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  3. Arcgis api for javascript学习笔记(4.5版本) - 点击多边形(Polygon)并高亮显示

    在现在的 arcgis_js_v45_api 版本中并没有直接提供点击Polygon对象高亮显示.需要实现如下几个步骤: 1.点击地图时,获取Polygon的Graphic对象: 2.对获取到的Gra ...

  4. 多线程编程 CreateThread(解释了TContext)

    function CreateThread( lpThreadAttributes: Pointer;           {安全设置} dwStackSize: DWORD;             ...

  5. Codeforces 449 B. Jzzhu and Cities

    堆优化dijkstra,假设哪条铁路能够被更新,就把相应铁路删除. B. Jzzhu and Cities time limit per test 2 seconds memory limit per ...

  6. C#将string转换为十六进制

    /// <summary>         /// 将string格公式为十六进制数据         /// </summary>         /// <param ...

  7. centos 7 构造iptables开放80port

    centos7默认是使用firewalld托管防火墙. 安装后centos7后,已安装nginxserver,但同样没有在一个局域网访问,我哥哥告诉我,我应该是一个防火墙以打开.防火墙关闭就可以了. ...

  8. Variability aware wear leveling

    Techniques are presented that include determining, for data to be written to a nonvolatile memory, a ...

  9. Objective-C block实现代码分析

    block内部结构 让我们写一个block void exampleBlock() { // NSConcreteStackBlock int a = 1; __block int b = 2; in ...

  10. java构造器的作用

    通常通过在构造器中传入参数,对字段进行初始化,以达到初始化所创建的对象实例的目的.