Delphi Error – E2191 EXPORTS allowed only at global scope

Delphi Compiler Error

E2191 EXPORTS allowed only at global scope

Reason for the Error & Solution

An EXPORTS clause has been encountered in the program source at a non-global scope.

program Produce;

  procedure ExportedProcedure;
  exports ExportedProcedure;
  begin
  end;

begin
end.

It is not allowed to have an EXPORTS clause anywhere but a global scope.

program Solve;

  procedure ExportedProcedure;
  begin
  end;

exports ExportedProcedure;
begin
end.

The solution is to ensure that your EXPORTS clause is at a global scope and textually follows all procedures named in the clause. As a general rule, EXPORTS clauses are best placed right before the source file’s initialization code.