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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with opendialog

Status
Not open for further replies.

scoopbh

Programmer
Feb 28, 2003
6
BR
I'm using opendialog to get a file name and put it in a string var (i dont need to load the file into memory, I only need the file name):

procedure TForm1.button1Click(Sender: TObject);
var
n: string;
begin

if opendialog1.Execute then
n:= opendialog1.FileName;

end;

It works well, but I get a error when I try to perform any file operations (like read or write to any file) after the use of opendialog.

Exists another way that I can select a filename without using the opendialog?
 
I don't think the error is with the opendialog bit. You can verify this by adding the following line after you assign the filename to n:
Code:
  MessageDlg(n, mtInformation, [mbOK], 0);

I presume that your problem is occurring in how you go about your file operations. If you post the code you are using and the associated error message, we'll be able to offer advice on it. Clive [infinity]
 
Looks OK to me as well!

Also scoopbh cound use

showmessage(n);

to debug the string contents.

I think you can be pretty confident with this construct for using opendialogs :-

with opendialog1 do
if execute then
n := filename;


Steve

 
I assume your problems arise bcause FileOpen dialog can change the current directory. Then maybe your consecuting file operations fail because of assigning a file name to a file without the complete path.

To solve this problem you have 2 ways:
1. In the FileDialog options select "ofNoChangeDir".
2. Assign file names with full path.

regards
Roderich
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top