title: What's the best way to URLEncode a file name in Delphi?
body: <p>My desktop application has to download a file from the internet.  The path to the file is known, the file name itself is semi variable, i.e. someone else will be putting new files there, and my application will have to download those.</p>
  
  <p>Now I want to make sure that the URL is safe, and that it will be interpreted correctly.  Also, if there's a '#' in a file name (you never know), I do want it to be encoded.  Javascript has two distinct functions for this: <code>encodeURI</code> and <code>encodeURIComponent</code>. The latter also encodes '#' characters, amongst other things.
  Of course, I could roll my own, but I figured that there’s bound to be functions ready for that, and I might as well avoid making some old mistake.</p>
  
  <p>I will be downloading the file with a object that uses the WinInet series of API functions (<a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa385096.aspx" rel="nofollow noreferrer">InternetOpen</a> and its ilk).</p>
  
  <p>So I started rummaging around on MSDN, and sure enough, there’s <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/bb773768.aspx" rel="nofollow noreferrer">UrlCanonicalize</a>. But there's also <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/bb773774%28v=vs.85%29.aspx" rel="nofollow noreferrer">UrlEscape</a>, <a href="http://msdn.microsoft.com/en-us/library/ms775098%28v=vs.85%29.aspx" rel="nofollow noreferrer">CreateUri</a> (but that’s not present in the Delphi 2010 units), and finally <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa384473%28v=vs.85%29.aspx" rel="nofollow noreferrer">InternetCreateUrl</a>, which requires me to split up the entire URL.  I’d rather concatenate the first portion of the URL with the URLEncoded filename.</p>
  
  <p>Also, they all have tons of different flags, different defaults which have changed over the course of the Windows versions, and I can’t figure out the differences anymore.  Does anybody know which one is best for this purpose?</p>