Solved

Problem with saving to textfile

Posted on 2000-05-05
3
235 Views
Last Modified: 2010-04-04
Why does my file end up in c:\documents instead of the folder of my program???

My procedure looks like this:

Procedure TForm1.SaveMyFile;
Var
F : TextFile;
Begin

   AssignFile(F,'myFile.txt');
   Rewrite(F);
   Try
      writeLn(F,'bla bla');
      .
      .
      .
   finally
     CloseFile(F);
   end;
end;

Hope you can help me :)
Retep
0
Comment
Question by:retep
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 17

Expert Comment

by:geobul
ID: 2781101
Hi,
The reason is not in the procedure above. Maybe there is a value 'Start in: c:\documents' in the shortcut. Maybe you change current directory somewhere in the code before saving the file.

Regards, Geo
0
 

Accepted Solution

by:
lz earned 50 total points
ID: 2781107
It depends on how your program was started what becomes the current directory. You cannot rely that the current directory is where your *.exe is. So, instead of

AssignFile(F,'myFile.txt');

use the following line

AssignFile(F, ExtractFilePath(Application.ExeName) + 'myFile.txt');

This will in all cases store the file in the same directory as your *.exe.
0
 

Author Comment

by:retep
ID: 2781249
Thanks :)
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question