Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2010-04

Dear FreePascal

7 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

彘

Dear FreePascal,

I have some questions when I am using Free Pascal

> firstly , I find that I Can't use hot-key "Ctrl+N" to add

a new line in the IDE.
and I think the Free Pascal's ide is not very stable, I am using fpc under a MS-DOS 7.1, sometimes when I am editing my sourse code(I chosed Microsoft Convention (Ctrl+X,Ctrl+V,Ctrl+C) ) if I pressed Ctrl+C

sometimes the ide will terminate and said like this: " The ide is terminated , save your soure code and restart the ide"

And sometimes if I use Alt+F and Commend Shell
the ide is still in my sight . Maybe it is because "Out of Memory"?

> secondly, if I want to debug my program when I use "step over F8"

the ide will display the user screen when I press F8. It is not the same as Turbo Pascal. I really dislike it ,but I don't know what to do.

> 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?

      {=======    The source code is below  ======= }
program ElementTable ;
{this program's purpose is to input The Periodic Table of Element }
type
 yuansu=record
  En_name:string[3];
  mole:real;
  period:1..7;
  group:string[5];
  end;
 var
 i:integer;
 dat:file of yuansu;
 jilu:array [1..112] of yuansu;
 BEGIN
    for i:=1 to 2 do
      jilu[i].period:=1;          (* Here is a input example :*)
    for i:= 3 to 10 do            (* En_name:= 'C'            *)
      jilu[i].period:=2;          (* mole:=12.0107            *)
    for i:= 11 to 18 do           (* period:=2                *)
      jilu[i].period:=3;          (* group:='IVA'             *)
    for i:= 19 to 36 do
      jilu[i].period:=4;
     for i:=37 to 54 do
      jilu[i].period:=5
      for i:=55 to 71 do
      jilu[i].period:=6;
      for i:=72 to 112 do
      jilu[i].period:=7;
   for i:=1 to 112 do
   begin
     write('name:');
     readln(jilu[i].EN_name);     {it terminated when it }
     write('mole:');              { runs to somewhere }
     readln(jilu[i].mole);        { around here}
     write('group:');
     readln(jilu[i].group);
   end;
     assign(dat,'dat.bin');
     {$i-} reset(dat);{$i+}
      if ioresult 0 then
         rewrite(dat);
         for i:=1 to 112 do
         write(dat,jilu[i]);
         close(dat);
         write(' ':10,'OK!');
         readln
 END.

Sincenrely
Andy Scout
2010.4.17

Reply by email

Bart
to 彘

Hi,

 and I think the Free Pascal's ide is not very stable,  I am using fpc under a MS-DOS 7.1,

This is plain DOS, or a DOS box in Win9x?

(The fp IDE in win9x DOS box used to be almost unworkable)

 >> 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?

Please give us the errormessage.

Bart

Reply by email

Bart
to 彘: I have some questions when I am using Free Pascal a new line in the IDE. and I think the…

Hi,

 >> 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?
Show quoted text 9 lines
  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.

Bart

Reply by email

Jürgen Hestermann
to Bart
Show quoted text 9 lines
> {$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.

Although I don't see the purpose of the above code snippet there is a difference between existing and non-existing file: If dat exists (and can be opened without error) then the rewrite is not done. So in this case dat is only opened for reading and existing data is not deleted (yet).

Reply by email

Bart
to Jürgen Hestermann

Hi Jurgen,

Show quoted text 5 lines
Although I don't see the purpose of the above code snippet there is a difference between existing and non-existing file: If dat exists (and can be opened without error) then the rewrite is not done. So in this case dat is only opened for reading and existing data is not deleted (yet).

That is correct, of course.
But, take a look at his code, after reset (open read/write) he starts writing 112 records to the file.
For the purpose of his program, the reset() is superfluous.

Bart

Reply by email

Bart
to 彘: I have some questions when I am using Free Pascal a new line in the IDE. and I think the…

Hi,

program ElementTable ; {this program's purpose is to input The Periodic Table of Element } type yuansu=record

I would also suggest changing that to

type
 yuansu= packed record

This will ensure that the size of the data (SizeOf(yuansu)) will be the same cross platfor and cross OS (16 vs 32 vs 64 bit systems). Otherwise you might not be able to read the file if you compile the program for a different architecture.

Bart

Reply by email

Jürgen Hestermann
to Bart: That is correct, of course. But, take a look at his code, after reset (open read/write)…
Show quoted text 9 lines
> Although I don't see the purpose of the above code snippet there is a > difference between existing and non-existing file: > If dat exists (and can be opened without error) then the rewrite is not > done. So in this case dat is only opened for reading and existing data is > not deleted (yet). That is correct, of course. But, take a look at his code, after reset (open read/write) he starts writing 112 records to the file. For the purpose of his program, the reset() is superfluous.

Yes, that's true.
But if the file is large,
it could happen that some parts of the file
survive this strange treatment.
So there is a difference in behaviour. ;-)

Nevertheless, we don't know what was intented.
Only the author can tell.

Reply by email