GetEnvironmentVariable Error (D7)

Giganews Newsgroups
Subject: GetEnvironmentVariable Error (D7)
Posted by:  Marcio Ehrlich (marcioehrlich_at_ig.com.br)
Date: Fri, 15 Sep 2006

I used this very routine with no problem at all with D5, but with D7 I am
getting the error "Ambiguous Overload Call to GetEnvironmentVariable"
function:

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;

Is there anything missing now?
Thanks,
Marcio

Replies