How to store and locate multiple interface types within a Delphi TInterfaceList
- by Brian Frost
Hi, I'm storing small interfaces from a range of objects into a single TInterfaceList 'store' with the intention of offering list of specific interface types to the end user, so each interface will expose a 'GetName' function but all other methods are unique to that interface type. For example here are two interfaces:
IBase = interface
//----------------------------------------
function GetName : string;
//----------------------------------------
end;
IMeasureTemperature = interface(IBase)
//------------------------------------
function MeasureTemperature : double;
//----------------------------------------
end;
IMeasureHumidity = interface(IBase)
//----------------------------------------
function MeasureHumidity: double;
//----------------------------------------
end;
I put several of these interfaces into a single TInterfaceList and then I'd like to scan the list for a specific interface type (e.g. 'IMeasureTemperature') building another list of pointers to the objects exporting those interfaces. I wish to make no assumptions about the locations of those objects, some may export more than one type of interface. I know I could do this with a class hierarchy using something like:
If FList[I] is TMeasureTemperature then ..
but I'd like to do something simliar with an interface type, Is this possible?