title: How do I get the handle for locking a file in Delphi?
body: <p>The <a href="http://msdn.microsoft.com/en-us/library/aa365202(VS.85).aspx" rel="nofollow noreferrer">LockFile</a> API takes a file handle. I normally use TStream for file access, so I'm unsure how to get the appropriate handle, given an ANSIString filename only. My purpose is to lock a file (which may not exist originally) during a process, write some information to other users, and then unlock and delete it. </p>
  
  <p>I would appreciate sample code or pointers to it to make this reliable. </p>