1

Topic: How to define, what file DLL is occupied?

Good afternoon!
At an application launch I define checksum of file DLL then the first application starts to use DLL.
At start of the second copy of the program the second copy starts to define checksum of this DLL. Error I/O error 32 jumps out.
Tried to check file employment, but at AssignFile (AFile, AFileName); in the second copy this error jumps out.

procedure TDM1.ActDLLExistsExecute (Sender: TObject);//Stock-taking DLL from the list
function isFileOpen (var f: File): boolean;
begin
with TFileRec (f) do
Result: = (Handle <> 0) and (Mode <> fmClosed);
end;
var fn: string; Ffs: File;
begin
QDLLFiles. Open;
while not QDLLFiles. Eof do
begin
fn:=DM1.QDLLFilesGoal.AsString+DM1.QDLLFilesName.AsString;
if not FileExists (fn) then begin
DM1.QDLLFilesBODY.SaveToFile (fn);
end
else begin
[b] AssignFile (Ffs, fn); [/b]//Here in the second copy error I/O error 32
Reset (Ffs);
if isFileOpen (Ffs) then//If this line is not present, an error in GetFileCRC (fn) as there too is AssignFile
if GetFileCRC (fn) <> DM1.QDLLFilesCRC.Value then begin
DM1.QDLLFilesBODY.SaveToFile (fn);
end;
CloseFile (Ffs);
end;
QDLLFiles. Next;
end;
QDLLFiles. Close;
end;

2

Re: How to define, what file DLL is occupied?

zeon11;
To copy a file dll in rate and there did not try to consider?

3

Re: How to define, what file DLL is occupied?

andreymx;
Good thought if other decision is not that I will use this council. Thanks.

4

Re: How to define, what file DLL is occupied?

zeon11;
Reset, on a default, opens a file in a mode +. Candidate solutions 2:
1. To do FileMode: = 0; but it .
2. To work with a file humanly, or FileOpen+FileRead or through file , specifying that the file opens only for reading (fmOpenRead Or fmShareDenyWrite).

5

Re: How to define, what file DLL is occupied?

zeon11 wrote:

andreymx;
Good thought if other decision is not that I will use this council. Thanks.

not, the bad my variant
Once again somewhere to copy

6

Re: How to define, what file DLL is occupied?

Kazantsev Alexey wrote:

zeon11;
Reset, on a default, opens a file in a mode +. Candidate solutions 2:
1. To do FileMode: = 0; but it .
2. To work with a file humanly, or FileOpen+FileRead or through file , specifying that the file opens only for reading (fmOpenRead Or fmShareDenyWrite).

I do not see a way as through TFileStream to define that the file is occupied by other application.
If only to use idea andreymx', not  with file employment, and at once through TFileStream to draw out a file in a safe place and there to define its checksum?

7

Re: How to define, what file DLL is occupied?

Kazantsev Alexey wrote:

zeon11;
Reset, on a default, opens a file in a mode +. Candidate solutions 2:
1. To do FileMode: = 0;
but it .
2. To work with a file humanly, or FileOpen+FileRead or through file , specifying that the file opens only for reading (fmOpenRead Or fmShareDenyWrite).

To Reset ' and unfortunately does not reach, takes off for AssignFile

8

Re: How to define, what file DLL is occupied?

zeon11 wrote:

I do not see a way as through TFileStream to define that the file is occupied by other application.

It is not necessary to define that it is occupied. It is necessary to make so that the file opened even if
It is occupied
.

9

Re: How to define, what file DLL is occupied?

Dimitry Sibiryakov wrote:

it is passed...
It is not necessary to define that it is occupied. It is necessary to make so that the file opened even if
It is occupied
.

So it not a problem. How from TFileStream to receive file checksum?

10

Re: How to define, what file DLL is occupied?

CRC it is algorithm which counts checksum on file contents.
TFileStream allows to receive contents, it is necessary contained to give this to function of calculation CRC.
P.S. When already from Delphi cut AssignFile and other carrion, well or enter the directive, which disconnects (and is better includes for compatibility) this disgrace....

11

Re: How to define, what file DLL is occupied?

zeon11 wrote:

To Reset ' and unfortunately does not reach, takes off for AssignFile

Actually takes off on Reset, simply the debugger shows a line behind that on which there was an error.

12

Re: How to define, what file DLL is occupied?

X-Cite wrote:

When already from Delphi cut AssignFile and other carrion, well or enter the directive, which disconnects (and is better includes for compatibility) this disgrace....

Nafiga? To whom does it hinder? And for reading of text files so generally anything is not present

13

Re: How to define, what file DLL is occupied?

zeon11 wrote:

As from TFileStream to receive file checksum?

In the same way as well as from File. Differences any.

14

Re: How to define, what file DLL is occupied?

zeon11, :
http://www.gunsmoker.ru/2011/10/pascal.html - the General principles of operation with files Pascal "," 3 see ". Further the file opens. To open a file it is possible in three modes...", about FileMode, and also more low - about error handling.
http://www.gunsmoker.ru/2011/11/blog-post_12.html - that it is necessary to use in the modern programs.

15

Re: How to define, what file DLL is occupied?

Made while so:
As determination CRC between AssignFile and Reset delivered FileMode: = 0;

.....
AssignFile (Fi, FileName);
FileMode: = 0;
Reset (Fi);
.......

Like a problem it is solved. Thanks.

16

Re: How to define, what file DLL is occupied?

In the fresh environments it is possible to look still, reading:
TFile. ReadAllBytes, TFile. ReadAllLines, TFile. ReadAllText
Record:
TFile. WriteAllBytes, TFile. WriteAllLines, TFile. WriteAllText, TFile. AppendText

17

Re: How to define, what file DLL is occupied?

zeon11 wrote:

like a problem it is solved. Thanks

Shoot.

18

Re: How to define, what file DLL is occupied?

GunSmoker wrote:

it is passed...
Shoot.

Nevertheless, thanks for links.