forward declaration of procedure in delphi

Seatless picture Seatless · May 13, 2013 · Viewed 7.9k times · Source

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
}

Answer

Mason Wheeler picture Mason Wheeler · May 13, 2013

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.