In general, when I totally don't understand something, I try and create a Lab environment where I can beat up on the problem until I begin to get some understanding. In my current project (The Big Project) I am separating all file interactions in one unit, building a table of all the files I may or may not be using, and then referencing them via the file handle.
To do this, I need to get the file handle - regardless of how I open it. FileOpen gives me the handle directly, but I can also get at the handle by using GetFileHandle (I think). So, I created the attached lab to explore TestFiles.zip).
I'm using only text files at this spoint - and Pascal source is a readily available text file!
When I select a file and open it with FileOpen, it returns a handle. When I select a file and open it with Assign/Reset/GetFileHandle it also returns a handle. In order to be able to test the 'open' process, I use the handle to close the file, if it is non-zero:
if testfilehandle > 0 then
closefile(testfile);
This works fine if I open with Assign/Reset/GetHandle and then try and close with FileClose or simply Close.
However, the same code, using the handle from FileOpen fails to close the file because it is not Open (even though no error seems to be reported).
The lab is (I think) fairly self-evident: Select a file (maybe one of the files from the unzipped project?), and then try various Open/Close sequences. The Top line of buttons use the handle-based routines from SysUtils, the bottom buttons use the traditional Pascal Reset routines.
I know this is obvious and staring me in the face - it's just that no matter how hard I stare back, I can't see it!
Grateful, as always, for any pointers and advice!
Tony