Sign in to follow this  

Pascal code in several files

This topic is 4710 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

lets say I have my code like this: Program myprog; function MyFunc(x:integer):integer; begin (* some code *) end; begin (* some code that uses the function above *) end. how can I split this into two files? one that containes the main program loop and the other that contains the function 'MyFunc' ? I have search on google and tried different things but nothing works for me, I'm using gpc on Solaris if that is an issue. Thanks in advance for your help.

Share this post


Link to post
Share on other sites
You have to write a Pascal Unit in order to do this. From my old Pascal book(Using Borland Pascal 7), this is what you have to do:


UNIT MyUnit;

INTERFACE (* NO NEED FOR A ; *)
(* Perhaps a USES statement here for required units *)
USES Crt;

(* Define the function prototypes here *)
function MyFunc(x : integer) : integer;
function AnotherFunc(n : integer) : integer;

(* Start the implementation *)
IMPLEMENTATION

function MyFunc(x : integer) : integer;
VAR
y : integer;
BEGIN
(* Code *)
END;

function AnotherFunc(n : integer) : integer;
VAR
z : integer;
BEGIN
(* Code *)
END;

END. (* End the unit *)


This is what I got from glancing through my Pascal book, not sure if it still works like that.

Toolmaker

Share this post


Link to post
Share on other sites

This topic is 4710 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this