tuskinhu

Classes

Oct 4th, 2013
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 4.79 KB | None | 0 0
  1. // Carregando a classe
  2. procedure CarregaDadosPC(G: Integer);
  3. var
  4.   uPC: TPedidoCompra;
  5.   uPCI: TPedidoCompraItem;
  6.   cPC, cPCI: Integer;
  7.   i, j: Integer;
  8.   str: string;
  9. begin
  10.   Randomize;
  11.  
  12.   for cPC := 0 to 10 do
  13.   begin
  14.     uPC := LstPC.Items.Adicionar;
  15.     uPC.Pedido := RandomRange(25000, 26000);
  16.     for cPCI := 1 to 15 do
  17.     begin
  18.       uPCI := uPC.Items.Adicionar;
  19.       uPCI.SeqItem := cPCI;
  20.       uPCI.Material := RandomRange(1000, 5000);
  21.     end;
  22.   end;
  23.  
  24.   str := '';
  25.   for i := 0 to LstPC.Items.Count - 1 do
  26.   begin
  27.     str := str + 'Pedido: ' + IntToStr(LstPC.Items[i].Pedido) + CrLf;
  28.  
  29.     for j := 0 to LstPC.Items[i].Items.Count - 1 do
  30.     begin
  31.       str := str + 'Pedido: ' + IntToStr(LstPC.Items[i].Pedido) + ' ' +
  32.                    'Item Seq: ' + IntToStr(LstPC.Items[i].Items[j].SeqItem) + ' ' +
  33.                    'Material: ' + IntToStr(LstPC.Items[i].Items[j].Material) + CrLf;
  34.     end;
  35.   end;
  36.  
  37.   ShowMessage(str);
  38. end;
  39.  
  40. // Classes
  41.  
  42. TPedidosCompras = class(TPersistent)
  43.   private
  44.     fListaPedidoCompra: TPedidosComprasCollection;
  45.     procedure SetItem(const Value: TPedidosComprasCollection);
  46.   public
  47.     constructor Create;
  48.     destructor Destroy; override;
  49.  
  50.     property Items: TPedidosComprasCollection read fListaPedidoCompra write SetItem;
  51.   end;
  52.  
  53.   TPedidosComprasCollection = class(TCollection)
  54.   private
  55.     function GetItem(Index: Integer): TPedidoCompra;
  56.     procedure SetItem(Index: Integer; Value: TPedidoCompra);
  57.   public
  58.     constructor Create(AOwner: TPedidosCompras);
  59.     function Adicionar(): TPedidoCompra;
  60.     property Items[Index: Integer]: TPedidoCompra read GetItem write SetItem; default;
  61.   end;
  62.  
  63.   TPedidoCompra = class(TCollectionItem)
  64.   private
  65.     fPedido: Integer;
  66.     fItensPedido:  TPedidoCompraItemCollection;
  67.  
  68.     procedure SetItem(const Value: TPedidoCompraItemCollection);
  69.   public
  70.     constructor Create; reintroduce;
  71.     destructor Destroy; override;
  72.  
  73.     property Pedido: Integer read fPedido write fPedido;
  74.     property Items: TPedidoCompraItemCollection read fItensPedido write SetItem;
  75.   end;
  76.  
  77.   TPedidoCompraItemCollection = class(TCollection)
  78.   private
  79.     function GetItem(Index: Integer): TPedidoCompraItem;
  80.     procedure SetItem(Index: Integer; Value: TPedidoCompraItem);
  81.   public
  82.     constructor Create(AOwner: TPedidoCompra);
  83.     function Adicionar(): TPedidoCompraItem;
  84.     property Items[Index: Integer]: TPedidoCompraItem read GetItem write SetItem; default;
  85.   end;
  86.  
  87.   TPedidoCompraItem = class(TCollectionItem)
  88.   private
  89.     fSeqItem: Integer;
  90.     fMaterial: Integer;
  91.   public
  92.     constructor Create; reintroduce;
  93.     destructor Destroy; override;
  94.      
  95.     property SeqItem: Integer read fSeqItem write fSeqItem;
  96.     property Material: Integer read fMaterial write fMaterial;
  97.   end;
  98.  
  99. { TPedidosCompras }
  100.  
  101. constructor TPedidosCompras.Create;
  102. begin
  103.   inherited Create;
  104.   fListaPedidoCompra := TPedidosComprasCollection.Create(Self);
  105. end;
  106.  
  107. destructor TPedidosCompras.Destroy;
  108. begin
  109.   fListaPedidoCompra.Free;
  110.   inherited;
  111. end;
  112.  
  113. procedure TPedidosCompras.SetItem(const Value: TPedidosComprasCollection);
  114. begin
  115.   fListaPedidoCompra.Assign(Value);
  116. end;
  117.  
  118. { TPedidosComprasCollection }
  119.  
  120. constructor TPedidosComprasCollection.Create(AOwner: TPedidosCompras);
  121. begin
  122.   inherited Create(TPedidoCompra);
  123. end;
  124.  
  125. function TPedidosComprasCollection.Adicionar: TPedidoCompra;
  126. begin
  127.   Result := TPedidoCompra(inherited Add);
  128.   Result.Create;
  129. end;
  130.  
  131. function TPedidosComprasCollection.GetItem(Index: Integer): TPedidoCompra;
  132. begin
  133.   Result := TPedidoCompra(inherited GetItem(Index));
  134. end;
  135.  
  136. procedure TPedidosComprasCollection.SetItem(Index: Integer; Value: TPedidoCompra);
  137. begin
  138.   inherited SetItem(Index, Value);
  139. end;
  140.  
  141. { TPedidoCompra }
  142.  
  143. constructor TPedidoCompra.Create;
  144. begin
  145.   fItensPedido := TPedidoCompraItemCollection.Create(Self);
  146. end;
  147.  
  148. destructor TPedidoCompra.Destroy;
  149. begin
  150.   fItensPedido.Free;
  151.   inherited;
  152. end;
  153.  
  154. procedure TPedidoCompra.SetItem(const Value: TPedidoCompraItemCollection);
  155. begin
  156.   fItensPedido.Assign(Value);
  157. end;
  158.  
  159. { TPedidoCompraItemCollection }
  160.  
  161. constructor TPedidoCompraItemCollection.Create(AOwner: TPedidoCompra);
  162. begin
  163.   inherited Create(TPedidoCompraItem);
  164. end;
  165.  
  166. function TPedidoCompraItemCollection.Adicionar: TPedidoCompraItem;
  167. begin
  168.   Result := TPedidoCompraItem(inherited Add);
  169.   Result.Create;
  170. end;
  171.  
  172. function TPedidoCompraItemCollection.GetItem(Index: Integer): TPedidoCompraItem;
  173. begin
  174.   Result := TPedidoCompraItem(inherited GetItem(Index));
  175. end;
  176.  
  177. procedure TPedidoCompraItemCollection.SetItem(Index: Integer; Value: TPedidoCompraItem);
  178. begin
  179.   inherited SetItem(Index, Value);
  180. end;
  181.  
  182. { TPedidoCompraItem }
  183.  
  184. constructor TPedidoCompraItem.Create;
  185. begin
  186.  
  187. end;
  188.  
  189. destructor TPedidoCompraItem.Destroy;
  190. begin
  191.  
  192.   inherited;
  193. end;
Advertisement
Add Comment
Please, Sign In to add comment