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!

Strange OpenDialog problem

Status
Not open for further replies.

KempCGDR

Programmer
Jan 10, 2003
445
GB
Ok, I have two forms in my project (well more actually, but they don't matter here). There is a button on the first one to go to the second one and when the second one is closed, the first one is displayed again.

On the second form is an OpenDialog that is called from a menu option. If this is done when running the program it does what it is meant to, but the first form displays a 'file not found' error when it executes a bit of code (shown below) to open the debug file to write what's happening to. No other circumstances trigger this error and I can't see why this should.

Code:

On the second form is (in the appropriate menu click event):

dlgLoad.InitialDir := DataDir;
dlgLoad.DefaultExt := '*.dbd';
dlgLoad.Filter := 'DeckBuild deck|*.dbd';
If dlgLoad.Execute then
begin
//A load of code commented out to see if it was the problem
end;

In the FormShow event of the first form:

If Debug then
begin
AssignFile(OutFile, 'Debug.txt');
Append(OutFile);
Writeln(OutFile, 'Opened Menu');
Writeln(OutFile);
Flush(OutFile);
end;

It dies on the Append with the message 'File not found'. This same file is successfully opened and written in many places, it this error only occurrs if the OpenDialog is executed, nothing else makes it happen. Any ideas anyone?
 
Executing your OpenDialog changes the current path of your application. So appending to "debug.txt" wont find this file in the other folder.

You can set OpenDialog option 'NoChangeDir' to avoid this.
Generally it is always a good way to supply the full path when assigning files, e.g. "C:\MyApp\Debug.txt" instead of just "Debug.txt".

Rod
 
Ok thanks, you learn something new every day.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top