Author Topic: Free Pascal produces runtime error 107  (Read 4706 times)


  • Newbie
  • Posts: 2
Free Pascal produces runtime error 107
« on: June 25, 2014, 04:01:44 pm »
...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?
« Last Edit: June 25, 2014, 04:36:24 pm by mggm »


  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Free Pascal produces runtime error 107
« Reply #1 on: June 25, 2014, 04:33:52 pm »
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.
Want quicker answers to your questions? Read

Open source including papertiger OCR/PDF scanning:

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified


  • Global Moderator
  • Hero Member
  • *****
  • Posts: 8471
  • FPC developer.
Re: Free Pascal produces runtime error 107
« Reply #2 on: June 25, 2014, 04:56:18 pm »
It seems to be the write(enum) functionality. If the conversion fails then this runtime error is raised.


  • Newbie
  • Posts: 2
Re: Free Pascal produces runtime error 107
« Reply #3 on: June 25, 2014, 05:09:45 pm »

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.
« Last Edit: June 25, 2014, 05:20:11 pm by mggm »


TinyPortal © 2005-2018