Advertisement
Guest User

TDictionary<TGUID,iDicInterface>

a guest
Dec 15th, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 2.57 KB | None | 0 0
  1. unit DictionaryFactory;
  2.  
  3. interface
  4.  
  5. uses
  6.   System.Generics.Collections, Dialogs;
  7.  
  8. type Tproduto = class
  9.  
  10.   procedure VenderProdutos(aCodeBar: string);
  11. end;
  12.  
  13.  
  14. type TClientes = class
  15.  
  16.      procedure cadastrarCliente( NomeCliente: string );
  17. end;
  18.  
  19. type iDicInterface = interface
  20. ['{F707C788-7886-4D58-A170-5C5609DCA9EC}']
  21.    procedure cadastrarCliente( NomeCliente: string );
  22.    procedure VenderProdutos(aCodeBar: string);
  23. end;
  24.  
  25. type TDicClass = class( TInterfacedObject,iDicInterface )
  26.   private
  27.     FTClientes: TClientes;
  28.     FTproduto: Tproduto;
  29.     function getFTClientes: TClientes;
  30.     procedure setFTClientes(const Value: TClientes);
  31.     function getFTproduto: Tproduto;
  32.     procedure setFTproduto(const Value: Tproduto);
  33.   public
  34.    property Produto: Tproduto read getFTproduto write setFTproduto;
  35.    property Myclass:TClientes read getFTClientes write setFTClientes;
  36.    procedure VenderProdutos(aCodeBar: string);
  37.    procedure cadastrarCliente( NomeCliente: string );
  38.      constructor Create; (*Metodos do Constructor*)
  39.      destructor Destroy; override;
  40.  
  41.    published
  42.    {Protected declaration}
  43.    end;
  44.  
  45. type
  46.      TObj = class function ObjT: TDictionary<TGUID,iDicInterface>;
  47.      end;
  48.  
  49. implementation
  50.  
  51. { TDicClass }
  52.  
  53. procedure TDicClass.cadastrarCliente(NomeCliente: string);
  54. begin
  55.   FTClientes.cadastrarCliente(NomeCliente);
  56. end;
  57.  
  58. constructor TDicClass.Create;
  59. begin
  60.  
  61. end;
  62.  
  63. destructor TDicClass.Destroy;
  64. begin
  65.  
  66.   inherited;
  67. end;
  68.  
  69. function TDicClass.getFTClientes: TClientes;
  70. begin
  71.   if not assigned( FTClientes ) then
  72.   begin
  73.      FTClientes := TClientes.Create;
  74.   end;
  75.    Result := FTClientes;
  76. end;
  77.  
  78. function TDicClass.getFTproduto: Tproduto;
  79. begin
  80.   if not assigned( FTproduto ) then
  81.   begin
  82.     FTProduto:= Tproduto.Create;
  83.   end;
  84.   Result := FTproduto;
  85. end;
  86.  
  87. procedure TDicClass.setFTClientes(const Value: TClientes);
  88. begin
  89.  FTClientes := value;
  90. end;
  91.  
  92. procedure TDicClass.setFTproduto(const Value: Tproduto);
  93. begin
  94.  FTproduto:= value;
  95. end;
  96.  
  97. procedure TDicClass.VenderProdutos(aCodeBar: string);
  98. begin
  99.   FTproduto.VenderProdutos(aCodeBar);
  100. end;
  101.  
  102. { TObj }
  103.  
  104. function TObj.ObjT: TDictionary<TGUID,iDicInterface>;
  105.  var Dic: TDictionary<TGUID,iDicInterface>;
  106. begin
  107.  dic:= TDictionary<TGUID,iDicInterface>.Create;
  108.  dic.Add(iDicInterface,TDicClass.Create);
  109.  Result:= dic;
  110. end;
  111.  
  112. { TClientes }
  113.  
  114. procedure TClientes.cadastrarCliente(NomeCliente: string);
  115. begin
  116.   showmessage(NomeCliente);
  117. end;
  118.  
  119. { Tproduto }
  120.  
  121. procedure Tproduto.VenderProdutos(aCodeBar: string);
  122. begin
  123.  showMessage(aCodeBar);
  124. end;
  125.  
  126. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement