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. Objective-C的基础数据结构

    类的数据结构 Class(指针) ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 typedef struct objc_c ...

  2. mysql 权限命令

    grant all on *.* to 'root' identified by 'root';

  3. 设计模式(四)The Factory Pattern 出厂模式

    一.简单工厂 定义:定义一个创建对象的接口,可是由其子类决定要实例化的对象是哪一个,工厂方法让类的实例化推迟到子类. 通俗的来讲就是由工厂方法确定一个框架.详细的实现由其子类来完毕. 与简单工厂相比, ...

  4. 浅谈WPF中对控件的位图特效(WPF Bitmap Effects)

    原文:浅谈WPF中对控件的位图特效(WPF Bitmap Effects) -------------------------------------------------------------- ...

  5. 漫步Unity3D(三)

    八.预制(Prefab) 仅此一点提出,由于它使用过于频繁. 还Unity 一中的核心要素.原本Unity你拖放模型到场景中的一个对象,或者,创建一个几何.或浅的地形.个物体的偏移.旋转和缩放.然后绑 ...

  6. hbase结合hive和sqoop实现数据指导mysql

    hive综合hbase两个优势表中的:     1.实现数据导入到MYSQL.     2.实现hbase表转换为另外一张hbase表.  三个操作环节:      1.hbase关联hive作为外部 ...

  7. Python实现多线程下载

    #!/usr/bin/python # -*- coding: utf-8 -*- # filename: paxel.py '''It is a multi-thread downloading t ...

  8. wpf 判断鼠标在一段时间内是否移动

    原文:wpf 判断鼠标在一段时间内是否移动 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/config_man/article/details/74 ...

  9. Windows 编译libcurl(openssl+zlib)(使用VC编译)

    libcurl主要功能就是用不同的协议连接和沟通不同的服务器,如果使用HTTPS,需要OpenSSL libcurl https://curl.haxx.se/download.html 下载Sour ...

  10. python_简单的DB统计

    import numpy as npimport pylab as pldates=['20170314','20170315','20170316','20170317','20170318','2 ...