Delphi 解析系统环境变量

时间:2022-12-03 06:50:55
// http://www.outofmemory.cn
function ExpandEnvironment(const strValue: string): string;
var
chrResult: array[..] of Char;
wrdReturn: DWORD;
begin
wrdReturn := ExpandEnvironmentStrings(PChar(strValue), chrResult, );
if wrdReturn = then
Result := strValue
else
begin
Result := Trim(chrResult);
end;
end;

使用范例
EditPath.Text := ExpandEnvironment('%systemroot%\Temp\');
在windows下输入如下结果
C:\Windows\Temp\