首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Delphi中向Codesite.Send传递接口

在Delphi中向Codesite.Send传递接口
EN

Stack Overflow用户
提问于 2014-03-15 08:00:29
回答 2查看 396关注 0票数 0

我无法让CodeSite.Send使用声明为接口的变量。编译时错误是E2250,没有可以用这些参数调用的重载版本的“发送”。

如何使用CodeSite接口?

演示问题的代码示例:

代码语言:javascript
复制
type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  end;

  IMyInterface = Interface(IInterface)['{9BCD2224-71F8-4CE7-B04C-30703809FAAD}']
    function GetMyValue : String;
    property MyVaue : String read GetMyValue;
  End;

  MyType = class(TInterfacedObject, IMyInterface)
    private
      sValue : string;
      function GetMyValue : String;
    published
      property MyVaue : String read GetMyValue;
  end;

var
  Form1: TForm1;
  test : IMyInterface;
  testType : MyType;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
  test := MyType.Create;
  testType := MyType.Create;
  CodeSite.Send( 'testType', testType );  // This compiles
  CodeSite.Send( 'test', test );  // Compiler error here
  FreeAndNil(test);
end;

function MyType.GetMyValue : String;
begin
  Result := Self.sValue;
end;
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-03-15 08:25:05

正如雷米在他的评论中指出的那样,当您指定一个接口时,CodeSite不知道要记录什么。即使有一个重载的发送接受IInterface,它也不会有任何帮助,因为它仍然不知道您的特定接口IMyInterface

我所知道的唯一解决办法是在实现类中实现ICodeSiteCustomData,并使用以下内容

代码语言:javascript
复制
CodeSite.Send( 'test', test as ICodeSiteCustomData);

请注意,此功能在CodeSite Express中不可用。

票数 2
EN

Stack Overflow用户

发布于 2014-03-15 09:06:47

我找到了另一种方法,可以发挥作用,但即使这样也有它的缺点。

引入一个用于TCodeSiteLogger的类助手,用于实现接口发送的过载。在内部,您将接口转换回实现实例,并将其用于发送。请注意,这将为您提供底层对象的所有已发布属性,而不仅仅是接口的属性。

代码语言:javascript
复制
type
  TCodeSiteLoggerHelper = class helper for TCodeSiteLogger
    procedure Send(const Msg: string; const Value: IInterface); overload;
  end;

procedure TCodeSiteLoggerHelper.Send(const Msg: string;
  const Value: IInterface);
begin
  Send(Msg, Value as TObject);
end;
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22421228

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档