[fpc-pascal] Dear FreePascal

Bart bartjunk64 at gmail.com
Tue Apr 20 16:52:15 CEST 2010


>  >> Tirdly, once I was programming a program (the source code is below)
>  when I input about 100 data the program occured a error ,then it
>  terminated. I don't why ,and I can't understand the Error Code it gives
>  to me.Can you find my error and fix it for me?

>   for i:=1 to 112 do
>   begin
>     write('name:');
>     readln(jilu[i].EN_name);
>     write('mole:');
>     readln(jilu[i].mole);               // <---------------- **
>     write('group:');
>     readln(jilu[i].group);               // <---------------- **
>   end;

This could be one reason it crashes:
When asking for input for "mole" or "group", when the user does not
enter a real/integer from 1..7 resp. (simple typo) the program will
crash with a runtime error.
You should read in a string, then try to convert it (and handle
possible conversion errors).

>     {$i-} reset(dat);{$i+}
>      if ioresult <>0 then
>         rewrite(dat);

Although not wrong, the purpose of this construction is not clear to me.
In every case you will end up overwriting all data in the file.
In that case you could simply do with a  rewrite(dat). The reset(dat)
is really not necessary.
If the file exists, rewrite will effectively clear it's contents. If
the file dowes not exist, rewrite will create an empty file for you.


More information about the fpc-pascal mailing list