Delphi 将接口用作已发布的链接属性
我正在尝试发布一个属性,该属性允许我在实现指定接口的所有组件之间进行选择。 有可能这样做吗 我尝试使用一个接口作为发布属性,但它似乎不起作用。 以下是我遵循的步骤: 我已经为测试定义了两个接口和三个对象:Delphi 将接口用作已发布的链接属性,delphi,properties,interface,components,Delphi,Properties,Interface,Components,我正在尝试发布一个属性,该属性允许我在实现指定接口的所有组件之间进行选择。 有可能这样做吗 我尝试使用一个接口作为发布属性,但它似乎不起作用。 以下是我遵循的步骤: 我已经为测试定义了两个接口和三个对象: uses Classes, Variants; type IMyInterfaceA = interface function FGetValue() : Variant; end; TMyObjectA = class(TComponent, IMyInterfa
uses
Classes, Variants;
type
IMyInterfaceA = interface
function FGetValue() : Variant;
end;
TMyObjectA = class(TComponent, IMyInterfaceA)
protected
FValue : Variant;
FAlternativeValueSource : IMyInterfaceA;
function FGetValue() : Variant;
published
property Value : Variant read FGetValue write FValue;
property AlternativeValueSource : IMyInterfaceA read FAlternativeValueSource write FAlternativeValueSource;
end;
IMyInterfaceB = interface
procedure DoSomething();
end;
TMyObjectB = class(TComponent, IMyInterfaceB)
public
procedure DoSomething();
end;
TMyObjectC = class(TComponent);
implementation
function TMyObjectA.FGetValue() : Variant;
begin
if((FValue = Null) AND (FAlternativeValueSource <> nil))
then Result := FAlternativeValueSource.FGetValue
else Result := FValue;
end;
procedure TMyObjectB.DoSomething();
begin
//do something
end;
我已将4个对象添加到表单中:
MyObjectA1: TMyObjectA;
MyObjectA2: TMyObjectA;
MyObjectB1: TMyObjectB;
MyObjectC1: TMyObjectC;
选择对象检查器的AlternativeValueSource
下拉列表中的MyObjectA1
,我可以看到所有具有接口的对象。(我只希望实现IMyInterfaceA
的MyObjectA1
和MyObjectA2
)
定义接口的GUID
IMyInterfaceA = interface
['{A5675798-F457-4E32-B0AA-608717CFD242}']
function FGetValue() : Variant;
end;
Delphi的IDE根据其GUID(设计时)标识接口。添加GUID后,一切都按要求开始工作。非常感谢。
IMyInterfaceA = interface
['{A5675798-F457-4E32-B0AA-608717CFD242}']
function FGetValue() : Variant;
end;