Recent

Author Topic: could not compile a simple program  (Read 1935 times)

fcu

  • Jr. Member
  • **
  • Posts: 89
could not compile a simple program
« on: January 13, 2019, 03:23:34 pm »
Hi
this simple code compiled fine with lazarus and raise an error with fpc default editor
also if i type (fpc main.pas) i got the same error
i thought assignfile is part of rtl , so is not necessary to include its unit !
note i have a fresh installation of fpc 3.0.4 win 32bits

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: could not compile a simple program
« Reply #1 on: January 13, 2019, 03:38:50 pm »
i thought assignfile is part of rtl , so is not necessary to include its unit !
note i have a fresh installation of fpc 3.0.4 win 32bits

AssignFile is included only if you set one of the modes that use objpas by default (DELPHI or OBJFPC) so you can either add {$MODE OBJFPC} or {$MODE DELPHI} (or use the equivalent compiler parameters):
Code: Pascal  [Select][+][-]
  1. {$mode objfpc}
  2. program test;
  3. var
  4.   f: textfile;
  5. begin
  6.   AssignFile(f, 'ATestFile.txt');
  7.   {... etc ...}
  8. end;

or use the good old Assign(file, filename)

Code: Pascal  [Select][+][-]
  1. program test;
  2. var
  3.   f: textfile;
  4. begin
  5.   Assign(f, 'ATestFile.txt');
  6.   {... etc ...}
  7. end;

Lazarus, by default, uses ObjFPC mode but the console IDE (and the command-line compiler) use FPC, the "Free Pascal dialect" mode. Thence the different result with each.

ETA: Note that you can also change mode in the options of the text-mode IDE: see attached image. Although my recomendation s to add it the "mode" switch in the source so that it applies always.
« Last Edit: January 13, 2019, 03:57:37 pm by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

fcu

  • Jr. Member
  • **
  • Posts: 89
Re: could not compile a simple program
« Reply #2 on: January 13, 2019, 04:17:35 pm »
aha thanks 
really i didn't  expect that the mode could be the cause
i thought fpc uses objfpc by default even if i don't set it explicitly 
anyway thanks for the info

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: could not compile a simple program
« Reply #3 on: January 13, 2019, 04:50:52 pm »
From the Users' Guide, chapter 7:
Quote
Currently, 5 modes are supported:
FPC   This is the original Free Pascal compiler mode: here all language constructs except classes, interfaces and exceptions are supported. Objects are supported in this mode. This is the default mode of the compiler.
[etc]
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

 

TinyPortal © 2005-2018