[fpc-pascal] Unicodestrings and Assign(File)
Sven Barth
pascaldragon at googlemail.com
Sat May 19 18:34:15 CEST 2012
On 19.05.2012 13:12, Jürgen Hestermann wrote:
> 2.) The Assign routine in \fpc\rtl\inc\file.inc overwrites the
> whole file data structure with zeros (using fillchar). The
> name has to be omitted from this action because it is now
> managed automatically. So Assign needs to be changed to:
>
> -----------------------------------------------------------
> Procedure Assign(out f:File;const NewName:string);
> { Assign Name to file f so it can be used with the file routines }
>
> Begin // Assign
> FillChar(FileRec(f).Handle,SizeOf(FileRec)-Sizeof(FileRec(f).name),0);
> FileRec(f).Handle := UnusedHandle;
> FileRec(f).mode := fmClosed;
> FileRec(f).Name := NewName;
> End; // Assign
> -----------------------------------------------------------
I just noticed: FillChar will be no problem here. It sets the name field
(which is an implicit pointer) to Nil which is equal to "empty string".
So no need to change the FillChar calls for FileRec (the only exception
might be if you FillChar an existing file passed by a "var", but then a
"finalize(f)" might be sufficient before calling FillChar).
Regards,
Sven
More information about the fpc-pascal
mailing list