Link to home
Start Free TrialLog in
Avatar of chiwan
chiwan

asked on

How to change ExtractFilePath(Application.ExeName) back?

I am writing a program, the user could
change skin of the program, I put the
exe file in c:\temp, and skin files in
c:\temp\skins, when user run this program, the
ExtractFilePath(Application.ExeName) is
c:\temp
After user click 'change skin' button, I use following procedure open a dialog
let user select skin.ini file:

procedure TForm1.cmSkinClick(Sender: TObject);
var   SkinsDlg : TOpenDialog;
begin
     SkinsDlg := TOpenDialog.Create(self);
     SkinsDlg.InitialDir := ExtractFilePath(Application.ExeName)+'Skins';
     SkinsDlg.Filter := 'Skin files (*.ini)|*.ini';
     if SkinsDlg.Execute then
     begin
          SkinForm1.LoadSkinFile(SkinsDlg.FileName);  //Change the skin
     end;
     SkinsDlg.Free;
end;


The problem is after user change skin,
the ExtractFilePath(Application.ExeName)
is c:\temp\skin, how to change it back
to c:\temp?

Thanks & Rgds

Chiwan
Avatar of florisb
florisb

Same problem if you use ExtractFilePath(ParamStr(0))?

And if you set the initial dir before you do OpenDialog?

Floris.

Chiwan,

ExtractFilePath(Application.ExeName) is not something that you can change thus I do not understand why you are getting this problem. Try assigning the Executable's path to a variable and then use that. Like so:

procedure TForm1.cmSkinClick(Sender: TObject);
var
   SkinsDlg : TOpenDialog;
   CurDir : String;
begin
   SkinsDlg := TOpenDialog.Create(self);
   CurDir := ExtractFilePath(Application.ExeName);
   SkinsDlg.InitialDir := (CurDir+'Skins');
   SkinsDlg.Filter := 'Skin files (*.ini)|*.ini';
   if SkinsDlg.Execute then begin
      SkinForm1.LoadSkinFile(SkinsDlg.FileName);  //Change the skin
   end;
   SkinsDlg.Free;
end;

Hope this helps,

Chris.
you could just call ExtractFilePath(application.exename) once when the program starts and store it in a variable(since the actual location of the .exe will not change during the course of running your program)
ASKER CERTIFIED SOLUTION
Avatar of Epsylon
Epsylon

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
are u there?
Ding dong!!!!!!
Please grade!
Please grade!
Please grade!
YEAH!
Another blacklist candidate..?
Chiwan, you are a waste of time......
Avatar of chiwan

ASKER

EPsylon
I am sorry, reply so later, my internet
connection was cut by our telecom. company because some argument between my boss and them.
Now I am in another city.
Live is not easy.