Forum > General
Interfaces and TFPGMaps
(1/1)
tt:
Good evening,
I have this
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit sample interface type IIntf = interface ['{00000000-0000-0000-0000-000000000000}'] function MakeSomething(inputValue: Integer): Integer; end; TImpl = class(TInterfacedObject, IIntf) // Implementation of IIntf function MakeSomething(inputValue: Integer): Integer; // Other methods function MakeSomethingElse(inputValue: Integer): Integer; end; implementation procedure TImpl.MakeSomething(inputValue: Integer): Integer;begin Result := inputValue + 1;end; procedure TImpl.MakeSomethingElse(inputValue: Integer): Integer;begin Result := inputValue + 2;end; end.
Then I have a situation in which I need a generic map <string, IIntf>, because I need using clients not to see the extra methods available on the implementations of IIntf.
Reading the documentation I understand that in this case I must use a TFPGMapInterfacedObjectData (because I am dealing with refcounted material) not a TFPGMap. Is this correct?
Then I also have another situation in which I need a generic map <string, TImpl>, because I need using clients to see all methods available on TImpl.
In this case should I use a TFPGMap<string, TImpl> or should I use a TFPGMapInterfacedObjectData<string, TImpl>?
The point is: is TFPGMapInterfacedObjectData necessary everytime we are using TInterfacedObject as a base class? or does it depend on what we put in the data part of the map?
Thanks
tt:
Reading more carefully documentation
https://www.freepascal.org/docs-html/current/rtl/fgl/tfpgmapinterfacedobjectdata.html
seems that I must use in both cases TFPGMapInterfacedObjectData.
Just please some guru to confirm.
Navigation
[0] Message Index