// 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\