views:

108

answers:

1
+1  Q: 

Record file error

Hello. I am using Delphi 2007 and I am trying to make record type file. In Delphi 7 there were no problems for me.

Type
Kompiuteris = record
...
end;
Failas = file of Kompiuteris;

But in Delphi 2007 I get problem. Error says that: Type "Kompiuteris" needs finalization. So, what is wrong?

+4  A: 

From the documentation:

Certain types are treated specially by the compiler on an internal basis in that they must be correctly finalized to release any resources that they might currently own. Because the compiler cannot determine what type is actually stored in a record's variant section at runtime, it is not possible to guarantee that these special data types are correctly finalized.

String is one of those data types which need finalization, and as such they cannot be stored in a File type.

glob
Ou... Now erethings getting clearer
gedO
If I use Delphi 2005 do I get the same error??
gedO
Yes. You would get the same error in *all* Delphi versions greater than or equal to 2. Perhaps you turned off the "long strings" compiler option.
Rob Kennedy
And how to turn it on??
gedO
@gedO: Look at {$H+}, {$H-} compiler directives.You always use a ShortString in a record and write it to a file. type TRec = record Name: ShortString; Age: Integer; end; fRec = file of TRec;Cheers.
jachguate
Thanks for ShortString, but were are {$H+}, {$H-} compiler directives? I am just begginer :)
gedO
Ged, please consider asking a new question: *How do I control the "long strings" compiler option?* There are several ways, and it's cumbersome to explain in the comments.
Rob Kennedy