Registriert seit: 16. Aug 2003
200 Beiträge
|
Re: Ende von MDI-Anwendungen erfahren
27. Sep 2009, 01:11
ungeprüft als Denkanstoß:
Delphi-Quellcode:
TFileAccessibleEvent = procedure(const Filename: string) of object;
TMyThread = class(TThread)
private
FFilename: string;
FOnDone: TFileAccessibleEvent;
procedure DoFileAccessible;
public
constructor Create(const Filename: string, ReadyEvent: TFileAccessibleEvent);
..
procedure TMyThread.Create(const Filename: string, ReadyEvent: TFileAccessibleEvent);
begin
inherited Create(True);
FreeOnTerminate := True;
FFilename := Filename;
FOnDone := ReadyEvent;
Resume;
end;
procedure DoFileAccessible;
begin
if Assigned(FOnDone) then
FOnDone(FFilename);
end;
procedure TMyThread.Execute;
var
h: THandle;
begin
repeat
h := CreateFile(PChar(FFilename),
GENERIC_READ, // dwDesiredAccess ist eigentlich egal
0, // dwShareMode 0 = Exklusiv
nil,
OPEN_EXISTING,
0,
0);
if h <> INVALID_HANDLE_VALUE then
begin
CloseHandle(h);
Synchonize(DoDone);
Terminate;
end else
if GetLastError = ERROR_SHARING_VIOLATION then
Sleep(500) //warten lohnt sich noch
else
Terminate;
until Terminated;
end;
|
|
Zitat
|