TURBO PASCAL |
Новости
|
30: How can I assign a value to an environment variable in TP?A: For assigning a value to (a parent process's) environment value you have to access and manipulate the Program Segment Prefix andMemory Control Blocks. This is a rather complicated undertaking. Asource code with an accompanying article by Trudy Neuhaus can befound in PC Magazine Volume 11 Number 1 pages 425-427. The budding TP programmers should note that the elementary trickof Exec (GetEnv('comspec'), '/c set key=whatever') will achieve onlya transient result for the duration of the exec shell. When you exit the shell after this endeavor, the environment will be as it was. Here is about the why. When the above command is executed, MS-DOSmakes a copy of the environment, and uses the copy. When the aboveshelling terminates, the copy of the environment is deleted, and theoriginal is restored. Hence the above trick cannot be used to changethe parent environment. If you don't want to try to go through this rather complicated task yourself, the routines "SETEVN Set a parent environment variable (variable=value)" "SETENVSH Set an environment variable for the duration of shelling"can be found in my TP TPU collection ftp://garbo.uwasa.fi/pc/ts/ tspa34*.zip (* = 40,50,55,60,70). No source code is included, nor available, though. From zeta@tcscs.com Gregory Youngblood: Fora source code see /pc/source/setenv.zoo at Garbo. One further detail. Users sometimes ask how one can change theprompt or the path from within a Turbo Pascal program. This is in noway different from changing the value of any other environment variable. Both PATH and PROMPT are environment variables that can beset with the MS-DOS SET command in the fashion described in theabove. This is not changed in any way by the fact that you can applyPROMPT and PATH also in an alternative format not requiring the SETcommand. |
(с)Все права защищены По всем интересующим вопросам прошу писать на электронный адрес |