con*_*tor 0 delphi interface function
我正在尝试调用一个函数从另一个单元返回一个接口; 例如,考虑以下内容:
program intf_sb1;
{$APPTYPE CONSOLE}
uses
myunit in 'myunit.pas';
var
MyBL: ISomeInterface;
begin
MyBL := GetInterface;
end.
Run Code Online (Sandbox Code Playgroud)
其内容myunit.pas如下:
unit myunit;
interface
type
ISomeInterface = interface
['{D25A26ED-7665-4091-9B0F-24DF37545E2A}']
end;
implementation
function GetInterface : ISomeInterface;
begin
end;
end.
Run Code Online (Sandbox Code Playgroud)
我的问题是,当我尝试运行此程序时,我收到错误"E2003 Undecleared identifier GetInterface".为什么不允许这样做?提前致谢!
Mar*_*ema 13
在接口部分也声明GetInterface函数.如果你不这样做,那么它就是"私人"的.
IE:
type
ISomeInterface
...
end;
function GetInterface: ISomeInterface;
implementation
function GetInterface: ISomeInterface;
begin
...
end;
Run Code Online (Sandbox Code Playgroud)