was ist neu ¦  programmier tips ¦  indy artikel ¦  intraweb artikel ¦  informationen ¦  links ¦  interviews
 sonstiges ¦  tutorials ¦  Add&Win Gewinnspiel

Tips (1541)

Dateien (137)
Datenbanken (90)
Drucken (35)
Grafik (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Mathematik (76)
Multimedia (45)
Oberfläche (107)
Objekte/
ActiveX (51)

OpenTools API (3)
Sonstiges (126)
Strings (83)
System (266)
VCL (242)

Tips sortiert nach
Komponente


Tip suchen

Tip hinzufügen

Add&Win Gewinnspiel

Werbung

29 Visitors Online


 
...den kompletten Pfad zur Programmdatei ermitteln?
Autor: Marc Dürst
Homepage: http://www.idev.ch
[ Tip ausdrucken ]  

Tip Bewertung (7):  
     


{*****************************************
Deutsch:
******************************************}

Die meisten von Euch kennen vermutlich die die Methode

MyFileName := Application.ExeName

mit welcher Ihr den Namen der aktuellen EXE oder DLL abfragen könnt. Soweit so gut. Der Haken dabei ist, dass dies bei Diensten, Control-Panel-Apps noch bei Web-Apps funktioniert, da diese "Application's" besagte Methode nicht haben. Eine Methode (aus den frühen Pascal-Zeiten), welche immer funktioniert ist das Kommando:

MyFileName := ParamStr(0);

Richtig! Es handelt sich um den 0-ten Kommandozeilenparameter. Windows macht das so, das dies der eigene Name ist. Wenn Ihr also in jedem Fall den Pfad zu Eurem Programm zur Laufzeit ermitteln wollte, geht das beispielsweise so:

MyFilePath := ExtractFilePath(ParamStr(0));


{*****************************************
ENGLISH:
******************************************}

As most of you know the method

MyFileName := Applicatoin.ExecName;

to get the filename (incl. path) to the current executable (exe or dll). Well, this is ok but doesn't work for things like service-apps, controlpanel-apps, web-apps, etc. as the application object of thouse doesn't have the ExecName property. A function which works in every case is

MyFileName := ParamStr(0);

You're right! It's the command line parameter number zero. This is the way Windows does it. If you'd like to get the path to your program at runtime your can do something like:

MyFilePath := ExtractFilePath(ParamStr(0));

 

Bewerten Sie diesen Tipp:

dürftig
ausgezeichnet


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners