Solved

File Access via exe Location

Posted on 2006-06-26
7
227 Views
Last Modified: 2010-04-05
Hi,

I'm making a simple tile based game so have many different images as the tiles, at the moment i am simply adding them all by typing in the full path location of each image into my code but want to make an editor which will save the location into a string.  But because if i save the full path, once the game is run on another machine the full path's will be different, so had the idea of saving the locations of the images in relation to the location of the executable.

For example if my structure was as follows
/game
/game/images
/game/executables

Is it possible to save the location of the images as game/images so it doesn't matter where the game folder is on the hardrive it will allways go up one level then into the images folder to loacte my tile images?!

Thanks for Help
0
Comment
Question by:James_h1023
  • 3
  • 2
  • 2
7 Comments
 
LVL 14

Expert Comment

by:Pierre Cornelius
ID: 16983104
use ExtractFilePath and PAramStr functions. like this:

ExePath:= ExtractFilePath(ParamStr(0));
ImagePath:= GamePath + 'images\';

regards
Pierre
0
 
LVL 4

Author Comment

by:James_h1023
ID: 16983130
Hi thanks for quick reponse.

I get the exePath bit but what is 'GamePath' is that a variable!? Thats the furthest up directory isn't it, but where is it coming from?

Cheers
James
0
 
LVL 8

Expert Comment

by:RickJ
ID: 16983136
Use the following as an example
var ThisDir : String ;

ThisDir := ExtractFilePath(Application.Exename) + 'games/images'
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 8

Expert Comment

by:RickJ
ID: 16983154
Oops sorry PierreC,
I did not see your post.
I was too slow....

PierreC gets the points.
0
 
LVL 14

Accepted Solution

by:
Pierre Cornelius earned 125 total points
ID: 16983155
Alternatively, in the LoadFromFile method call use relative path

e.g. Image1.Picture.LoadFromFile('..\Images\SomePic.bmp');
0
 
LVL 4

Author Comment

by:James_h1023
ID: 16983170
Thanks for quick help
James
0
 
LVL 14

Expert Comment

by:Pierre Cornelius
ID: 16983174
Sorry, GamePath Should have been ExePath.

My first example will be fine with the following dir structure

c:\game {exe goes here}
c:\game\images

if you prefer the following dir structure, rather use relative path in loadfromfile:
c:\game
c:\game\exe
c:\game\images
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

895 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now