Ver Mensaje Individual
  #4  
Antiguo 23-09-2008
Avatar de seoane
[seoane] seoane is offline
Miembro Premium
 
Registrado: feb 2004
Ubicación: A Coruña, España
Posts: 3.717
Reputación: 24
seoane Va por buen camino
Se me ocurre algo como esto:
Código Delphi [-]
function InsertarVariables(Str: String): String;
var
  i: Integer;
  EnvBlock, P: PChar;
begin
  Result:= Str;
  EnvBlock:= GetEnvironmentStrings;
  if EnvBlock <> nil then
  try
    with TStringList.Create do
    try
      P:= EnvBlock;
      while P^ <> #0 do
      begin
        if Pos('=',String(P)) > 1 then
          Add(String(P));
        inc(P,StrLen(P)+1);
      end;
      for i:= 0 to Count - 1 do
        Result:= StringReplace(Result,'%'+ Names[i] +'%', ValueFromIndex[i],
          [rfIgnoreCase,rfReplaceAll]);
    finally
      Free;
    end;
  finally
    FreeEnvironmentStrings(EnvBlock);
  end;
end;

// Por ejemplo
ShowMessage(InsertarVariables('%Windir%\miprograma.exe'));
Responder Con Cita