Hi all! i have a problem. From my database im streaming out a file and will save it with
filestream.savetostrem() method into the windows temp directory. thats work correctly. after that i open the file with the shellexecute command.

and the question: on forms close event: make a method to see all files stilled open.
i tryed this code but dosnt work:

function TInUse.IsUsed: Boolean;

var

FileHandle: HFILE;

begin

Result:=False;

if FileExists(FFileName) then begin

FileHandle:=CreateFile(PChar(FileName),GENERIC_READ or GENERIC_WRITE,0,Nil,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0);

Result:=FileHandle=INVALID_HANDLE_VALUE;

CloseHandle(FileHandle);

end;

end;

any idee?

1. Use the function IOResult that would find the error code.
2.Try this:
CreateFile(pchar(filename),GENERIC_READ or GENERIC_WRITE, FILE_SHARE_READ or FILE_SHARE_WRITE,nil,OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,0);

1. Use the function IOResult that would find the error code.
2.Try this:
CreateFile(pchar(filename),GENERIC_READ or GENERIC_WRITE, FILE_SHARE_READ or FILE_SHARE_WRITE,nil,OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,0);

thx for the list, but IOResult always returns with Zero (no problem), CreateFile...=INVALID_HANDLE_VALUE always returns true. So i dont know how i can check a file status (open/close). But i will try any other typs, idees.

Have you tried OpenFile() in OF_SHARE_EXCLUSIVE mode ?

Have you tried OpenFile() in OF_SHARE_EXCLUSIVE mode ?

hi!
i open files with this:
shellexecute(Handle, 'open', pchar(filename)), nil, nil, SW_SHOWNORMAL);

No, I mean to check if it is used, instead of the CreateFile() you posted.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.