Forum > General

Free Pascal produces runtime error 107


...which is not listed here: . I thought this document was meant to be exhaustive, or was I wrong?

Here is what I did:
a) Compiled a simple piece of code with no compiler options - simply fpc wont.pas
b) Used the compiled code to produce file wont.dat (inserted a 0 on standard input)
c) Screwed up the produced file
d) Tried to use the compiled code to open the screwed up file wont.dat (inserted a 1 on standard input).
e) Received:
Runtime error 107 at $00000000004002CD

EDIT: I've run into a yet another thingy I can't understand while playing with the sample.

I slighlty modified the code: Running the code (it does not crash with the {$I-} switch now) and commenting the writelns in and out showed that IOResult is set to 0! But removing the {$I-} switch immediately produces the above runtime error. I find this weird, becouse if I understand the documentation of the switch , the program with {$I-} should have IOResult set to something other then 0 if and only if the same program in the same conditions, but with {$I+} would crash. Yet there happenes the opposite: the program with {$I+} crashes, but with {$I-} reports no errors with IOResult. Why so?

Yes, it's meant to be exhaustive for current stable FPC (i.e. 2.6.4).

In any case, you could go grep through the source code to find the exact error number... (but if 107 exists on FPC 2.6.4 then it is a bug in the documentation, yes)

Please always specify what FPC/Lazarus version you are using, and operating system (see first link in my signature). Thanks.

It seems to be the write(enum) functionality. If the conversion fails then this runtime error is raised.


So, I'm on Linux Mint 16, Cinnamon. Well, it's FPC 2.6.2 , so maybe that's the reason...

Anyway, I found something with grep. It's file /rtl/inc/, lines 536-543. They read:

procedure fpc_shortstr_enum(ordinal,len:sizeint;typinfo,ord2strindex:pointer;out s:shortstring);[public,alias:'FPC_SHORTSTR_ENUM'];compilerproc;
  res: longint;
  if (res<>0) then

Edit: @marcov, it seems it is how you say. But if so, why {$I-} prevents the program from crashing?

Well, the program crashes because it can't handle the enum correctly. But {$I-} should prevent it from crashing only if it couldn't read the data correctly. But no errors araised there, since IOResult continues to be set to 0!

Edit2: Ahh, I get it. Now the program prints out nicely 107. The error araises on an attempt to write g, not to read the file . Anyway, IOResult code 107 again is not documented:

Seems I'll have to compile & run the program on an up-to-date fpc version.


[0] Message Index

Go to full version