【发布时间】:2014-03-15 08:00:29
【问题描述】:
我无法让 CodeSite.Send 使用声明为接口的变量。编译时错误是 E2250 没有可以使用这些参数调用的“发送”的重载版本。
如何在 CodeSite 中使用接口?
演示问题的代码示例:
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;
【问题讨论】:
-
如果它确实接受了一个接口,你希望它记录什么?
MyValue? CodeSite 如何知道访问该特定属性? RTTI?据我所知,接口没有Send()的重载,这就是您收到错误的原因。