Solved

File Access via exe Location

Posted on 2006-06-26
7
231 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
[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
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
LAN or WAN ? 11 119
update joined tables 2 72
How to add columns to a RAD Studio FMX grid at design time 1 58
IP without any Dots 1 99
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

732 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