Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Problem with saving to textfile

Posted on 2000-05-05
3
Medium Priority
?
238 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
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 200 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

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…
Integration Management Part 2
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

972 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