views:

106

answers:

1

I'm trying to call a function returning an interface from another unit; for instance consider the following:

program intf_sb1;
{$APPTYPE CONSOLE}
uses
  myunit in 'myunit.pas';
var
  MyBL: ISomeInterface;
begin
  MyBL := GetInterface;
end.

where the content of myunit.pas is as follows:

unit myunit;
interface
type
  ISomeInterface = interface
    ['{D25A26ED-7665-4091-9B0F-24DF37545E2A}']
  end;
implementation

function GetInterface : ISomeInterface;
begin
end;

end.

My problem is that I get the error "E2003 Undecleared identifier GetInterface" when I try to run this program. Why isn't this allowed? Thanks in advance!

+12  A: 

Declare the GetInterface function in the interface section as well. If you don't it is "private" to the unit.

IE:

type
  ISomeInterface
  ...
  end;

  function GetInterface: ISomeInterface;

implementation

function GetInterface: ISomeInterface;
begin
...
end;
Marjan Venema