WriteStr() or Write() or WriteLn() with a non existing enum value will break all Write() for the rest of the program or until WriteStr() or Write() is used with an existing enum again.
Consider the following minimal program:
program project1;
{$IOChecks off}
type
TFoo = (
FOO_A = 0,
FOO_B = 1,
FOO_Z = 25
);
var
E: TFoo;
S: String;
begin
WriteLn('FPC Version: ' + {$I %FPCVersion});
// This enum value does not exist!
E := TFoo(2);
WriteLn('Value is ', Ord(E));
// This will break Write() for the rest of the program
WriteStr(S, E);
WriteLn(S);
Writeln('WriteLn() is broken now!');
WriteStr(S, 42);
Writeln(S); // still broken
WriteStr(S, 'XYZ');
Writeln(S); // still broken
// WriteStr() with an existing enum value will "fix" it again
WriteStr(S, TFoo(0));
Writeln(S);
Writeln('WriteLn() is working again');
end.
The output of the above is:
FPC Version: 3.2.3
Value is 2
FOO_A
WriteLn() is working again
Is this intended behavior? I doubt it!