Board index » delphi » reset and rewrite incompatible types (newbie question)

reset and rewrite incompatible types (newbie question)

Hi everyone.

I am trying to compile a Pascal program, originally to be compiled
with Sun Pascal compiler. My computer is running Redhat Linux 7.3
(Kernel 2.4.18), and I am using the Free Pascal Compiler v1.0.6. I
know nothing about programming in Pascal and couldn't figure out
what's wrong with this program. Here is the error message from the
compiler:

Free Pascal Compiler version 1.0.6 [2002/05/23] for i386
Copyright (c) 1993-2002 by Florian Klaempfl
Target OS: Linux for i386
Compiling preplink.p
preplink.p(324,16) Error: Incompatible type for arg no. 2: Got
NAMESTR, expected LONGINT
preplink.p(360,19) Error: Incompatible type for arg no. 2: Got
NAMESTR, expected LONGINT
preplink.p(1968) Fatal: There were 2 errors compiling module, stopping

Here are the two parts of the program that cause the problems:

BEGIN  {readdata}
  writeln('Enter input file name (press only Enter to skip)');
  getfilename(filename);
  {If first character is blank -> skip}
  if filename[1]=' ' then goto 99;
  reset(indata,filename); /* THIS IS LINE 324 CAUSING FIRST ERROR */

/* SOME LINES SKIPPED HERE */

PROCEDURE writedata;
LABEL 66;
VAR
  i,j,k,systemm,nhap:integer;

BEGIN {writedata}
  writeln('Enter output file name - a file by the same name will be
overwritten!');
  writeln('Press only Enter to skip');
  getfilename(f);
  if f[1]=' ' then goto 66;
  rewrite(outfile,f); /* THIS IS LINE 360 CAUSING SECOND ERROR */

Here are the declarations on top of the source file that I think are
relevant to the problem (a lot of lines skipped):

PROGRAM preplink(input,output,indata,outfile);
 {Unix, for Sun Pascal pc compiler}

CONST
 namelength=20;     {for external file names}

TYPE
 namestr = packed array[1..namelength] of char;

VAR
 f,filename:namestr;
 outfile,indata:text;

I guess the second parameter of reset and rewrite might be a
compiler-specific extension. Any help would be very much appreciated.

Thanks,

Alex

 

Re:reset and rewrite incompatible types (newbie question)


Quote
Alexandre Irrthum wrote:

> I am trying to compile a Pascal program, originally to be compiled
> with Sun Pascal compiler. My computer is running Redhat Linux 7.3
> (Kernel 2.4.18), and I am using the Free Pascal Compiler v1.0.6. I
> know nothing about programming in Pascal and couldn't figure out
> what's wrong with this program. Here is the error message from the
> compiler:

> Free Pascal Compiler version 1.0.6 [2002/05/23] for i386
> Copyright (c) 1993-2002 by Florian Klaempfl
> Target OS: Linux for i386
> Compiling preplink.p
> preplink.p(324,16) Error: Incompatible type for arg no. 2: Got
> NAMESTR, expected LONGINT
> preplink.p(360,19) Error: Incompatible type for arg no. 2: Got
> NAMESTR, expected LONGINT
> preplink.p(1968) Fatal: There were 2 errors compiling module, stopping

> Here are the two parts of the program that cause the problems:

> BEGIN  {readdata}
>   writeln('Enter input file name (press only Enter to skip)');
>   getfilename(filename);
>   {If first character is blank -> skip}
>   if filename[1]=' ' then goto 99;
>   reset(indata,filename); /* THIS IS LINE 324 CAUSING FIRST ERROR */

> /* SOME LINES SKIPPED HERE */

> PROCEDURE writedata;
> LABEL 66;
> VAR
>   i,j,k,systemm,nhap:integer;

> BEGIN {writedata}
>   writeln('Enter output file name - a file by the same name will be
> overwritten!');
>   writeln('Press only Enter to skip');
>   getfilename(f);
>   if f[1]=' ' then goto 66;
>   rewrite(outfile,f); /* THIS IS LINE 360 CAUSING SECOND ERROR */

> Here are the declarations on top of the source file that I think are
> relevant to the problem (a lot of lines skipped):

> PROGRAM preplink(input,output,indata,outfile);
>  {Unix, for Sun Pascal pc compiler}

> CONST
>  namelength=20;     {for external file names}

> TYPE
>  namestr = packed array[1..namelength] of char;

> VAR
>  f,filename:namestr;
>  outfile,indata:text;

> I guess the second parameter of reset and rewrite might be a
> compiler-specific extension. Any help would be very much appreciated.

It is.  Ideally, there would be no second parameter, and the
system would know the correlation between internal and external
file names from the command line that started the program (PascalP
did this).

In practice, many systems use an optional second parameter (as you
did).  Others leave the reset procedure unchanged, and add an
'assign' procedure to make the connection.  It is usually called
as:

     assign(f, filename);

after which you can use the reset in its original form, i.e.

     reset(f);

So you should look up how reset (and possibly assign) function ON
YOUR SYSTEM.

--
Chuck F (cbfalco...@yahoo.com) (cbfalco...@worldnet.att.net)
   Available for consulting/temporary embedded and systems.
   <http://cbfalconer.home.att.net>  USE worldnet address!

Re:reset and rewrite incompatible types (newbie question)


Quote
CBFalconer <cbfalco...@yahoo.com> wrote in message <news:3DBAA89D.8A64FD86@yahoo.com>...
> In practice, many systems use an optional second parameter (as you
> did).  Others leave the reset procedure unchanged, and add an
> 'assign' procedure to make the connection.  It is usually called
> as:

>      assign(f, filename);

> after which you can use the reset in its original form, i.e.

>      reset(f);

> So you should look up how reset (and possibly assign) function ON
> YOUR SYSTEM.

I works fine with assign. Thanks a lot.

Other Threads