<p>Is there a way to check if a file has been opened by ReWrite in Delphi? </p>

<p>Code would go something like this:</p>

<pre><code>AssignFile(textfile, 'somefile.txt');
if not textFile.IsOpen then
   Rewrite(textFile);
</code></pre>

You can get the filemode. (One moment, I'll create an example).
TTextRec(txt).Mode gives you the mode:
```
```
55216 = closed
55217 = open read
55218 = open write

fmClosed = $D7B0;
fmInput  = $D7B1;
fmOutput = $D7B2;
fmInOut  = $D7B3;
```
```
Search TTextRec in the system unit for more information.