1
2 unit Unit1;
3
4 interface
5
6 uses
7 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
8 Dialogs, StdCtrls;
9
10 type
11 TForm1 = class(TForm)
12 Button1: TButton;
13 OpenDialog1: TOpenDialog;
14 procedure Button1Click(Sender: TObject);
15 private
16 { Private declarations }
17 public
18 { Public declarations }
19 end;
20
21 var
22 Form1: TForm1;
23
24 implementation
25
26 {$R *.dfm}
27
28 function IsFileInUse(const fName: TFileName): Boolean;
29 var
30 HFileRes: HFILE;
31 begin
32 Result := False;
33 HFileRes := CreateFile(PChar(fName),
34 GENERIC_READ or GENERIC_WRITE,
35 0,
36 nil,
37 OPEN_EXISTING,
38 FILE_ATTRIBUTE_NORMAL,
39 0);
40 Result := (HFileRes = INVALID_HANDLE_VALUE);
41 if not Result then
42 CloseHandle(HFileRes);
43 end;
44
45
46 procedure TForm1.Button1Click(Sender: TObject);
47 begin
48 if OpenDialog1.Execute then
49 if IsFileInUse(Opendialog1.FileName) then
50 ShowMessage('File is in use!')
51 else
52 ShowMessage('File NOT in use!');
53
54 end;
55 end.
56
|