Recent

Author Topic: testing initialization/finalization using an online compiler - doesn't work  (Read 595 times)

aja_ttara

  • New Member
  • *
  • Posts: 13
Hi,
I am learning Pascal and now I'm trying to use a module with simple initialization/finalization sections. I'm doing it using an online compiler (https://www.onlinegdb.com/online_pascal_compiler#) because I can't install Lazarus on my PC at work.

The main module is:
program test;
uses testing;
begin
  writeln('running');
end.

and the secondary module (called testing.pas) is:
unit testing;
interface
implementation
initialization
  writeln('starting');
finalization
  writeln('ending');
end.

It should work but it returns an error with exit code 254 instead.
Does anybody knows why?
Thanks beforehand

Thaddy

  • Hero Member
  • *****
  • Posts: 18519
  • Here stood a man who saw the Elbe and jumped it.
That is a wrong online compiler.
The online compilers usually do not allow you to use units.
Initialization inside of the main program is not allowed, so I doubt if you can test that with an online compiler: it is only allowed in units (modules).

BTW:
This has a better compiler: https://glot.io/new/pascal which runs 3.2.2, which is the current release.

You can test units, though:
Code: Pascal  [Select][+][-]
  1. unit testme;
  2. interface
  3. var s: string;
  4.    function testme:string;
  5. implementation
  6.    function testme:string;
  7.    begin
  8.       writeln;
  9.    end;
  10. initialization
  11.    writeln('Well..');
  12. end.
Then you have to make sure the online compiler sees it as testme.pas and be able to save it and use it online as a saved unit...... No online compiler is stupid enough to allow that....
But you can check the syntax......  :D

What you really need is an install to learn all features properly, not the online versions.
« Last Edit: November 18, 2025, 06:14:57 pm by Thaddy »
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

aja_ttara

  • New Member
  • *
  • Posts: 13
+1
Thank you so much for your explanation, I had the suspicion it was because of the online compiler. And thanks for the tip to a better one!

You are right, I'd need to work directly in Lazarus but I can do it only at home. I study Pascal at the office when I have some spare time but I don't have the permits necessary to install Lazarus on my PC. I wish there was a way to get around the admin at work  :D

creaothceann

  • Full Member
  • ***
  • Posts: 223
You could bring a laptop to work.

aja_ttara

  • New Member
  • *
  • Posts: 13
+1
You're right, that's another possibility :)

Handoko

  • Hero Member
  • *****
  • Posts: 5506
  • My goal: build my own game engine using Lazarus
... I can't install Lazarus on my PC at work.

Maybe you can download portable Lazarus and save it to a USB flashdisk so you can run it on your office computer. Portable program means you can run it without installing and it does not require you to left any data in the local drive of the computer. I haven't tried but I hear people frequently talk about portable Lazarus:

https://forum.lazarus.freepascal.org/index.php/topic,72657.msg569195.html#msg569195

creaothceann

  • Full Member
  • ***
  • Posts: 223
[...] and save it to a USB flashdisk

Reminds me of my computer science teacher in the '90s: "By the way, Turbo Pascal fits onto a single floppy disk and that's all I'm gonna say about this".

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12566
  • FPC developer.
Maybe it is just the matter of Lazarus pre enabling mode objfpc, and the online compiler running in plain "fpc" mode ?

Try adding {$mode objfpc}{$h+} in program and units.

 

TinyPortal © 2005-2018