如题....
解决方案 »
- Delphi7的代码提示问题
- 谁能给个dephi6.0的下载地址
- 我是新手,有个傻问题需要大家帮忙!
- [生日帖]散分200.
- 新手问题。。。
- 一段时间没来,连版面换了都不知道,呵呵,散点分,顺便求个算法,如下:
- 为什么
- 有谁知道使用tquery控件,如何读到当前记录的记录号;
- delphi中的Mapx应用中出现Error 没有注册类别,然后弹出Access vilation at address 0055F09A in module 'main.exe'.read of address 000002C
- //////////***********一个通常问题!************////////////
- 相同表结构的连接?
- 如何在Tchart的X轴设置显示日期和时间
function ProtectFile(sFilename : string) : hFile;
var
hf: hFile;
lwHFileSize, lwFilesize: longword;
ofs : TOFStruct;
begin
if FileExists(sFilename) then
begin
hf := OpenFile(pchar(sFilename), ofs, OF_READ or OF_WRITE or OF_SHARE_EXCLUSIVE);
if hf <> 0 then
begin
lwFilesize := GetFileSize(hf, @lwHFileSize);
if LockFile(hf, 0, 0, lwFilesize, lwHFilesize) then
Result := hf else Result := 0;
end
else Result := 0;
end
else Result := 0;
end;function UnProtectFile(hf: hFile): boolean;
begin
if hf <> 0 then
CloseHandle(hf);
end;procedure TForm1.Button1Click(Sender: TObject);
begin
protectedFile := ProtectFile(ExtractFilePath(Application.Exename)+'test.txt');
if protectedFile = 0 then
MessageBox(Handle, 'Error locking file!', '', MB_OK or MB_ICONERROR) else
Button1.Enabled := False;
end;procedure TForm1.Button2Click(Sender: TObject);
var
plik: TextFile;
data: string;
begin
UnProtectFile(protectedFile); AssignFile(plik, 'test.txt');
Reset(plik);
Read(plik, data);
CloseFile(plik); protectedFile := ProtectFile(ExtractFilePath(Application.Exename)+'test.txt');
ShowMessage(data);
end;
DOS下搞定你独占打开?不就用不了?这好吗?API Hook?Windows下有用而已http://lysoft.7u7.net
function ProtectFile(sFilename : string) : hFile;
var
hf: hFile;
lwHFileSize, lwFilesize: longword;
ofs : TOFStruct;
begin
if FileExists(sFilename) then
begin
hf := OpenFile(pchar(sFilename), ofs, OF_READ or OF_WRITE or OF_SHARE_EXCLUSIVE);
if hf <> 0 then
begin
lwFilesize := GetFileSize(hf, @lwHFileSize);
if LockFile(hf, 0, 0, lwFilesize, lwHFilesize) then
Result := hf else Result := 0;
end
else Result := 0;
end
else Result := 0;
end;function UnProtectFile(hf: hFile): boolean;
begin
if hf <> 0 then
CloseHandle(hf);
end;procedure TForm1.Button1Click(Sender: TObject);
begin
protectedFile := ProtectFile(ExtractFilePath(Application.Exename)+'test.txt');
if protectedFile = 0 then
MessageBox(Handle, 'Error locking file!', '', MB_OK or MB_ICONERROR) else
Button1.Enabled := False;
end;procedure TForm1.Button2Click(Sender: TObject);
var
plik: TextFile;
data: string;
begin
UnProtectFile(protectedFile); AssignFile(plik, 'test.txt');
Reset(plik);
Read(plik, data);
CloseFile(plik); protectedFile := ProtectFile(ExtractFilePath(Application.Exename)+'test.txt');
ShowMessage(data);
end;
那当然是在windows下,在DOS下有啥意义;
硬盘分区当然尽可能是NTFS的,以免人拿去挂DOS下面。