我无法让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;发布于 2014-03-15 08:25:05
正如雷米在他的评论中指出的那样,当您指定一个接口时,CodeSite不知道要记录什么。即使有一个重载的发送接受IInterface,它也不会有任何帮助,因为它仍然不知道您的特定接口IMyInterface。
我所知道的唯一解决办法是在实现类中实现ICodeSiteCustomData,并使用以下内容
CodeSite.Send( 'test', test as ICodeSiteCustomData);请注意,此功能在CodeSite Express中不可用。
发布于 2014-03-15 09:06:47
我找到了另一种方法,可以发挥作用,但即使这样也有它的缺点。
引入一个用于TCodeSiteLogger的类助手,用于实现接口发送的过载。在内部,您将接口转换回实现实例,并将其用于发送。请注意,这将为您提供底层对象的所有已发布属性,而不仅仅是接口的属性。
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;https://stackoverflow.com/questions/22421228
复制相似问题