On 5 Mar 2005 at 2:46, Waldek Hebisch wrote:
Frank Heckenbach wrote:
First of all, fjf659o.pas is a strange test program anyway. I was wondering about it, and it was on my list of things to have a closer look at again. So if it fails now, I don't consider it serious anyway.
It's supposed to test that `Finalize' does something for files. But what exactly it does, might better be left undefined. So, when the test program checks for a I/O error that can be caught, this might simply be too optimistic. (And file handling has changed internally since it was written, so it's possible that originally, it either caused a bad access that wasn't noticed, as now, or it didn't and does now.)
I think that it is not nice to crash. IMHO we should very clearly state in the documentation that access to a variable after calling `Finalize' on it is illegal, or make it more robust.
BTW do Delphi allow `Finalize' on files?
Yes. But with this "hint": 'Expression needs no Initialize/Finalize'.
From what I can see, "Finalize" does nothing to files - e.g., you can
still read from a file after Finalizing it (as long as it has not been Closed).
This is the Delphi 7 help information on Finalize:
"procedure Finalize( var V [; Count: Integer] );
Description
Finalize should be used only in Delphi code where a dynamically allocated variable is deallocated by other means than the Dispose procedure. Dynamic arrays can never be deallocated using the Dispose procedure, but can be freed by passing them to Finalize.
For global variables, local variables, objects, and dynamic variables deallocated using Dispose, the compiler generates code that finalizes all long strings, variants, and interfaces contained by the variable when the instance is destroyed.
If a dynamic variable meets the following two conditions, a call to Finalize is required to finalize the variable before it can be deallocated.
The variable is deallocated by other means than the Dispose standard procedure (for example using FreeMem). The variable contains long strings, variants, or interfaces, not all of which are empty or Unassigned.
Finalize simply sets all long strings to empty and all variants and interfaces to Unassigned, thus properly releasing any memory that was referenced by the long strings and variants.
In cases where several variables are deallocated in a contiguous memory block such as a dynamically allocated array of strings, the additional Count parameter can be specified to finalize all variables in one operation.
If the variable specified in a call to Finalize contains no long strings, variants, or interfaces, the compiler eliminates the call and generates no code for it."
Best regards, The Chief -------- Prof. Abimbola A. Olowofoyeku (The African Chief) web: http://www.greatchief.plus.com/