Delphi and Kylix

Moderators: pritaeas
Number of threads: 7264
Number of posts: 19073

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
obtaining directory path Posted by _yilmaz on 2 Nov 2004 at 8:01 AM
hi;

I want to obtain the exact directory which the executable itself resides in. I use the GetDir() procedure, but it returns the directory of the parameter file.

Thanx...
Report
Re: obtaining directory path Posted by Seri on 2 Nov 2004 at 9:37 AM
: hi;
:
: I want to obtain the exact directory which the executable itself resides in. I use the GetDir() procedure, but it returns the directory of the parameter file.
:
: Thanx...
:

Do you mean the path for your application itself ?
I don't have Delphi here but it's in the Application component.
Something like Application.ExeName if I remember right. And to obtain the path respectively you can use ExtractFilePath (not so sure about the name of the function either).
Hope that helps.
Report
Re: obtaining directory path Posted by zibadian on 2 Nov 2004 at 12:36 PM
: : hi;
: :
: : I want to obtain the exact directory which the executable itself resides in. I use the GetDir() procedure, but it returns the directory of the parameter file.
: :
: : Thanx...
: :
:
: Do you mean the path for your application itself ?
: I don't have Delphi here but it's in the Application component.
: Something like Application.ExeName if I remember right. And to obtain the path respectively you can use ExtractFilePath (not so sure about the name of the function either).
: Hope that helps.
:
You can also use the GetParam() function for that. The zeroth param is the complete exe-name including the path. This can also be used in a console application without the 400 kB forms overhead.
Report
Re: obtaining directory path Posted by _yilmaz on 3 Nov 2004 at 12:57 AM
Thanks to both. I need this to keep some additional text data related to the application.

Is it good to keep such data in the same directory with the .exe file or is there any other way to do this?

(I don't want to use an absolute path like "C:\Program Files\My Applicaton\" because the user may want to install the application to some other location he/she wants)

: : : hi;
: : :
: : : I want to obtain the exact directory which the executable itself resides in. I use the GetDir() procedure, but it returns the directory of the parameter file.
: : :
: : : Thanx...
: : :
: :
: : Do you mean the path for your application itself ?
: : I don't have Delphi here but it's in the Application component.
: : Something like Application.ExeName if I remember right. And to obtain the path respectively you can use ExtractFilePath (not so sure about the name of the function either).
: : Hope that helps.
: :
: You can also use the GetParam() function for that. The zeroth param is the complete exe-name including the path. This can also be used in a console application without the 400 kB forms overhead.
:

Report
Re: obtaining directory path Posted by zibadian on 3 Nov 2004 at 3:54 AM
: Thanks to both. I need this to keep some additional text data related to the application.
:
: Is it good to keep such data in the same directory with the .exe file or is there any other way to do this?
:
: (I don't want to use an absolute path like "C:\Program Files\My Applicaton\" because the user may want to install the application to some other location he/she wants)
:
: : : : hi;
: : : :
: : : : I want to obtain the exact directory which the executable itself resides in. I use the GetDir() procedure, but it returns the directory of the parameter file.
: : : :
: : : : Thanx...
: : : :
: : :
: : : Do you mean the path for your application itself ?
: : : I don't have Delphi here but it's in the Application component.
: : : Something like Application.ExeName if I remember right. And to obtain the path respectively you can use ExtractFilePath (not so sure about the name of the function either).
: : : Hope that helps.
: : :
: : You can also use the GetParam() function for that. The zeroth param is the complete exe-name including the path. This can also be used in a console application without the 400 kB forms overhead.
: :
:
:
Getting the exe-path in run-time is the best way to ensure that that data file is in the same directory as the exe-file. It also makes the program easier to remove from the system. If you have a lot of data, you might also consider using a subdirectory in the exe-directory. Most games use this method. That is also very easy to implement once you have the exe-path.
Report
Re: obtaining directory path Posted by Chesso on 3 Nov 2004 at 4:29 AM
This message was edited by Chesso at 2004-11-3 4:30:39

Just a code example of how i usually do it.

Procedure TForm1.Create(Sender: TObject);
Var
ExePath: String;
Begin
ExePath := ExtractFilePath(Application.ExeName);
End;

Just so you know this will give the path to the dir you exe resides in no / at the end like this c:\myprograms\game is how it would come out.

Or of course global rather then redoing it all the time if you refer to it alot.
Report
Re: obtaining directory path Posted by Seri on 3 Nov 2004 at 6:22 AM
: Thanks to both. I need this to keep some additional text data related to the application.
:
: Is it good to keep such data in the same directory with the .exe file or is there any other way to do this?
:
: (I don't want to use an absolute path like "C:\Program Files\My Applicaton\" because the user may want to install the application to some other location he/she wants)
:
You can use:
RootPath = ExtractFilePath(Application.ExeName)
or
RootPath = ExtractFilePath(GetParam(0))
Then you can have things like:
DataPath = RootPath + '\Data'
Use it whenenver needed:
AssignFile(f, DataPath + 'config.sys')
Hope this helps.
Report
Re: obtaining directory path Posted by Seri on 3 Nov 2004 at 6:23 AM
: : : hi;
: : :
: : : I want to obtain the exact directory which the executable itself resides in. I use the GetDir() procedure, but it returns the directory of the parameter file.
: : :
: : : Thanx...
: : :
: :
: : Do you mean the path for your application itself ?
: : I don't have Delphi here but it's in the Application component.
: : Something like Application.ExeName if I remember right. And to obtain the path respectively you can use ExtractFilePath (not so sure about the name of the function either).
: : Hope that helps.
: :
: You can also use the GetParam() function for that. The zeroth param is the complete exe-name including the path. This can also be used in a console application without the 400 kB forms overhead.
:
That is a very good idea indeed.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.