Newsgroups : Borland : borland.public.delphi.nativeapi.win32 : 2007 Jun : Share Violation
| Subject: | Share Violation |
| Posted by: | "Patrick Hughes" (duhvinci@-removethis-engds.com) |
| Date: | Fri, 15 Jun 2007 11:13:32 |
I'm getting a share violation as I am attempting to delete a previously
created directory structure;
Procedure DeleteFilesInDir(directory: String; Prompt: boolean);
Var
OpStruct:TSHFileOpStruct;
Begin
if Length(directory) = 0 then
Exit;
// Make sure that the passed directory name is terminated by a double#0.
// The following method works even if long strings are disabled.
AppendStr(directory, #0#0);
Fillchar( OpStruct, Sizeof(OpStruct), 0);
With OpStruct Do Begin
Wnd:=GetActiveWindow;
wFunc:=FO_DELETE;
pFrom:= @directory[1];
if Prompt then
fFlags := FOF_ALLOWUNDO or FOF_SILENT or FOF_NOCONFIRMATION
else
fFlags := FOF_ALLOWUNDO or FOF_SILENT;
End;
SHFileOperation(OpStruct);
End;
The code segment where I call the DeleteFilesInDir:
PrevDir := FLocation;
if CheckBox11.Checked then
begin
SaveDialog1.InitialDir := FLocation;
if SaveDialog1.Execute then
begin
CanClose := true;
FName := ExtractFileName(Copy(SaveDialog1.FileName, 0,
Length(SaveDialog1.FileName) - 4));
FLocation := ExtractFilePath(SaveDialog1.FileName);
end
else
exit;
end;
if (PrevDir = FLocation) and (CanClose = true) then
//share violation caused here>
DeleteFilesInDir(Copy(FLocation, 0, Length(FLocation) - 1),
CheckBox13.Checked);
>Program goes on to create the newly selected files and directories
The SaveDialog closes but I can't seem to get the SaveDialog to release it's
grip. Apparently I'm not understanding the excecute and close mechanism.
Thanks for any ideas,
Patrick Hughes