I see you have tagged your question [delphi]
as well as [pascal]
, so I guess you are in fact writing Delphi code. Then you got a few more options, besides caring about the order of the procedures and the forward
directive discussed by David.
Most often a Delphi
project (GUI or console) is divided into "units". A typical unit looks like this:
unit MyUnit;
interface
const
RANDOM_NUMBER = 17;
var
PrintExtraNiceMessage: boolean;
procedure DoThis;
procedure DoThat;
implementation
const
BUFFER_SIZE = 256;
procedure InitSomething;
begin
// TODO: do some internal work...
end;
procedure DoThis;
begin
// TODO: do something
end;
procedure DoThat;
begin
// TODO: do something else
end;
You will notice that the unit is divided in two parts: the interface
part, and the implementation
part. The interface
part contains only declarations (of functions, procedures, types, constants, and variables); the functions and procedures declared here are defined (that is, implemented) in the implementation
section. Notice that there can be functions and procedures defined in the implementation
section that have no declarations in the interface
section.
The grand idea is that the contents of the interface
section is visible to all other units in your program, whereas the contents of the implementation
section is only visible inside this very unit. So any other unit in your program can use the RANDOM_NUMBER
constant, the PrintExtraNiceMessage
variable and the two procedures DoThis
and DoThat
. But you can only use InitFunction
in this very unit (for instance, inside DoThis
or DoThat
). In addition, the constant BUFFER_SIZE
is not visible outside this very unit, either.
This is a very elegant approach. The interface
section describes how this unit is used in other units (e.g., what functions there are and how they are used), and the implementation details are "hidden" in the implementation
section.
A benefit of this approach is that it solves your problem, at least possibly. If the add
, multiply
, subtract
, and divide
procedures should be visible to other units, then they should be declared in the interface
section. But then they are indeed known to the compiler by the time it comes to your questiontype
procedure, and so you can use call these even if they are defined (implemented) below the questiontype
procedure inside the implementation
section. But, on the other hand, if it makes no sense at all to let other units use these procedures, then they should not be declared in the interface
section, and you need to do as David suggests. This also applies if you have no normal units at all in your project, that is, if you only have the program
file, which has no division into interface
and implementation
parts.