Mega Code Archive

 
Categories / Delphi / Examples
 

Getting a value from a DOS environment variable

Title: Getting a value from a DOS environment variable Question: If you need to get a value from a DOS environmente variable, this code will welcome Answer: function GetDOSEnvVar ( const VarName: string ): string; var len: integer; pDosEnv: PChar; begin result :=''; len := length ( varName ); PDosEnv := GetEnvironmentStrings; if ( StrLIComp ( PDosEnv, @VarName [ 1 ], len ) = 0) and ( PDosEnv [ len ] = ' ' ) then begin result := strPas ( PDosEnv + len + 1 ); break; end; inc ( PDosEnv, strLen ( PDosEnv ) + 1 ); end;