I am trying to publish a property that allows me to choose between all components that implement the specified interface. Can I do something like this?
I tried using the interface as a published property, but it does not seem to work. Here are the steps I followed:
I defined two interfaces and three objects for testing:
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;
Then I registered TMyObjectA, TMyObjectBand TMyObjectCin the development time package:
procedure Register();
begin
RegisterComponents('MyTestComponents', [
TMyObjectA,
TMyObjectB,
TMyObjectC
]);
RegisterPropertyInCategory('Linkage', TMyObjectA, 'AlternativeValueSource');
end;
I added 4 objects to the form:
MyObjectA1: TMyObjectA;
MyObjectA2: TMyObjectA;
MyObjectB1: TMyObjectB;
MyObjectC1: TMyObjectC;
Having selected MyObjectA1, in the drop-down list AlternativeValueSourceof the object inspector, I see all the objects that have an interface. (I only expected MyObjectA1and MyObjectA2that implement IMyInterfaceA)
