Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

OpenDialog.execute lock the folder 1

Status
Not open for further replies.

FamWS

Programmer
Jul 17, 2002
28
MY
Hi,
I am using Delphi v7.0 to create an Open dialog box to open a file.

After calling .Execute, the folder that is being accessed in Opendialog box will be locked until the whole application is terminated.

Is there any way that I can release the lock of the folder without terminating the application?

The reason being is I need to rename the folder after openning a file.

Any help will be appreciated.

Regards,
 
Hi FamWS

As far as I see it, it's not the problem of OpenDialog, it's the way the file system works. What I mean is that you can not rename/delete a folder if you have opened a file from that folder.

--- McMerfy
 
Thanks for your input,

But even I do not do anything after the execute command, i.e. I purposely remark all the codes after the execute command, the folder is still locked until the application is terminated.

if opendialog.execute then
begin
{
:
:
}
end;

 
try to change the initialfolder property of the opendialog after the execute command

--------------------------------------
What You See Is What You Get
 
I have tried, but it doesn't work.
Only when I open another file in another folder, then the lock to the folder is released.

Just wonder what is being locked and how to release it.

Anyone has any idea?

Thanks in advance.
 
and what if you create the opendialog component on the fly and free it afterwards? (sorry have no time to test this for the moment...)

Daddy

--------------------------------------
What You See Is What You Get
 
FamWS:

add

OpenDialog1.Options := [ofNoChangeDir];

either in code or set it in the options if it is on your form.

Tested it both ways and was able to rename the directory immediately with the test app still running.

Code:
1.

Var
  OpenDialog1 : TOpenDialog;
:
:
Begin
  OpenDialog1 := TOpenDialog.Create(Application);
  OpenDialog1.Options := [ofNoChangeDir];
  If (OpenDialog1.Execute) Then
    Showmessage('File is: '+OpenDialog1.FileName;
  OpenDialog1.Destroy;
End;

2.

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    OpenDialog1: TOpenDialog;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

:
procedure TForm1.Button2Click(Sender: TObject);
begin
  OpenDialog1.Options := [ofNoChangeDir];
  if (OpenDialog1.Execute) Then
    ShowMessage('File Obtained '+OpenDialog1.FileName);
end;



Regards and HTH,
JGS
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top