Reputation: 193
How can I make a forward declaration of a procedure in Delphi and make it's implementation in other place? I want to do something like this C's code but in Delphi:
void FooBar();
void FooBar()
{
// Do something
}
Upvotes: 8
Views: 10530
Reputation: 34909
Here is one way of doing it, through the interface/implementation part of a unit.
Unit YourUnit;
Interface
procedure FooBar(); // procedure declaration
Implementation
// Here you can reference the procedure FooBar()
procedure FooBar();
begin
// Implement your procedure here
end;
You should also take a look into the documentation about forward declarations
, where another option is mentioned, like @MasonWheeler answered.
Upvotes: 6
Reputation: 84550
You do that with the forward
directive, like so:
procedure FooBar(); forward;
...
//later on
procedure FooBar()
begin
// Do something
end;
This is only necessary if you're declaring it as an internal function. (ie. already inside the implementation
section of your unit.) Anything declared as a method of a class, or in the interface
section of the unit, is automatically understood to be forward-declared.
Upvotes: 22