[fpc-devel]Format() incompatibility with Delphi
Michalis Kamburelis
michalis at camelot.homedns.org
Fri Nov 7 19:08:58 CET 2003
Hi
What should
Format('%d %d %0:d %d', [0, 1, 2, 3])
return ? Delphi help is clear about that : "Setting the index specifier
affects all subsequent formatting", so it should return '0 1 0 1' (and
it does when compiled with Delphi).
FPC help is not clear about that. And unfortunately it turns out that
Format() implemented in FPC's SysUtils does not behave like in Delphi:
Format() call mentioned above returns '0 1 0 2' when compiled with FPC
(so it is like "Setting the index specifier _does not_ affect subsequent
formatting").
To fix this (i.e., make it Delphi-compatible) you have to change in file
sysstr.inc in function Checkarg at line 862 (as of latest FPC version
from CVS) from
if Index=-1 then
begin
DoArg:=Argpos;
inc(ArgPos);
end
else
DoArg:=Index;
to
if Index=-1 then
DoArg:=Argpos else
DoArg:=Index;
ArgPos:=DoArg+1;
This fix may broke existing code (that depends on the way how Format()
in FPC works) but I guess that such code may be considered buggy anyway
since FPC documentation was not clear about whether setting index
specifier affects subsequent formatting or not. Besides, if you want to
make Format() fully Delphi-compatible, there is no other way to fix
this, you have to change it's present behaviour.
BTW, I would also advice adding some notes about that to the FPC
SysUtils.Format documentation.
Regards,
Michalis Kamburelis <michalis at camelot.homedns.org>
More information about the fpc-devel
mailing list