48: What is the name of
the current Turbo Pascal program?
A: The name of the
currently executing Turbo Pascal program is in
ParamStr(0).
This was introduced in TP version 5.0, and as far as I recall at
least MS-DOS version 3.0 is required. For TP 4.0 you can use
"ParamStr0 The name of the program" from TSUNT45
in
ftp://garbo.uwasa.fi/pc/ts/tspa3440.zip (or whatever the version
number is the latest).
It is advisable to put the value into a string variable at be
beginning of the program before eny I/O takes place. Thus you
might
wish to use:
var progname : string;
begin { the main program }
progname := ParamStr(0);
:
A bonus of this method is that you can access the individual
characters of progname (e.g. progname[1] for the drive) while that
is not possible to do for the ParamStr keyword.