Registriert seit: 1. Feb 2018
3.691 Beiträge
Delphi 11 Alexandria
|
AW: Das Handle ist ungültig
6. Mai 2018, 21:25
Delphi-Quellcode:
function GetEnvVarValue(const VarName: string): string;
var
BufSize: Integer; // buffer size required for value
begin
// Get required buffer size (inc. terminal #0)
BufSize := GetEnvironmentVariable(PChar(VarName), nil, 0);
if BufSize > 0 then
begin
// Read env var value into result string
SetLength(Result, BufSize - 1);
GetEnvironmentVariable(PChar(VarName),
PChar(Result), BufSize);
end
else
// No such environment variable
Result := '';
end;
procedure TForm1.Button1(Sender: TObject);
begin
ShowMessage(GetEnvVarValue('SystemRoot'));
end;
hoffe es hilft!
edit
Delphi-Quellcode:
function ExpandEnvironment(const strValue: string): string;
var
chrResult: array[0..1023] of Char;
wrdReturn: DWORD;
begin
wrdReturn := ExpandEnvironmentStrings(PChar(strValue), chrResult, 1024);
if wrdReturn = 0 then
Result := strValue
else
begin
Result := Trim(chrResult);
end;
end;
Geändert von KodeZwerg ( 6. Mai 2018 um 21:28 Uhr)
|
|
Zitat
|