Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Carregando a classe
- procedure CarregaDadosPC(G: Integer);
- var
- uPC: TPedidoCompra;
- uPCI: TPedidoCompraItem;
- cPC, cPCI: Integer;
- i, j: Integer;
- str: string;
- begin
- Randomize;
- for cPC := 0 to 10 do
- begin
- uPC := LstPC.Items.Adicionar;
- uPC.Pedido := RandomRange(25000, 26000);
- for cPCI := 1 to 15 do
- begin
- uPCI := uPC.Items.Adicionar;
- uPCI.SeqItem := cPCI;
- uPCI.Material := RandomRange(1000, 5000);
- end;
- end;
- str := '';
- for i := 0 to LstPC.Items.Count - 1 do
- begin
- str := str + 'Pedido: ' + IntToStr(LstPC.Items[i].Pedido) + CrLf;
- for j := 0 to LstPC.Items[i].Items.Count - 1 do
- begin
- str := str + 'Pedido: ' + IntToStr(LstPC.Items[i].Pedido) + ' ' +
- 'Item Seq: ' + IntToStr(LstPC.Items[i].Items[j].SeqItem) + ' ' +
- 'Material: ' + IntToStr(LstPC.Items[i].Items[j].Material) + CrLf;
- end;
- end;
- ShowMessage(str);
- end;
- // Classes
- TPedidosCompras = class(TPersistent)
- private
- fListaPedidoCompra: TPedidosComprasCollection;
- procedure SetItem(const Value: TPedidosComprasCollection);
- public
- constructor Create;
- destructor Destroy; override;
- property Items: TPedidosComprasCollection read fListaPedidoCompra write SetItem;
- end;
- TPedidosComprasCollection = class(TCollection)
- private
- function GetItem(Index: Integer): TPedidoCompra;
- procedure SetItem(Index: Integer; Value: TPedidoCompra);
- public
- constructor Create(AOwner: TPedidosCompras);
- function Adicionar(): TPedidoCompra;
- property Items[Index: Integer]: TPedidoCompra read GetItem write SetItem; default;
- end;
- TPedidoCompra = class(TCollectionItem)
- private
- fPedido: Integer;
- fItensPedido: TPedidoCompraItemCollection;
- procedure SetItem(const Value: TPedidoCompraItemCollection);
- public
- constructor Create; reintroduce;
- destructor Destroy; override;
- property Pedido: Integer read fPedido write fPedido;
- property Items: TPedidoCompraItemCollection read fItensPedido write SetItem;
- end;
- TPedidoCompraItemCollection = class(TCollection)
- private
- function GetItem(Index: Integer): TPedidoCompraItem;
- procedure SetItem(Index: Integer; Value: TPedidoCompraItem);
- public
- constructor Create(AOwner: TPedidoCompra);
- function Adicionar(): TPedidoCompraItem;
- property Items[Index: Integer]: TPedidoCompraItem read GetItem write SetItem; default;
- end;
- TPedidoCompraItem = class(TCollectionItem)
- private
- fSeqItem: Integer;
- fMaterial: Integer;
- public
- constructor Create; reintroduce;
- destructor Destroy; override;
- property SeqItem: Integer read fSeqItem write fSeqItem;
- property Material: Integer read fMaterial write fMaterial;
- end;
- { TPedidosCompras }
- constructor TPedidosCompras.Create;
- begin
- inherited Create;
- fListaPedidoCompra := TPedidosComprasCollection.Create(Self);
- end;
- destructor TPedidosCompras.Destroy;
- begin
- fListaPedidoCompra.Free;
- inherited;
- end;
- procedure TPedidosCompras.SetItem(const Value: TPedidosComprasCollection);
- begin
- fListaPedidoCompra.Assign(Value);
- end;
- { TPedidosComprasCollection }
- constructor TPedidosComprasCollection.Create(AOwner: TPedidosCompras);
- begin
- inherited Create(TPedidoCompra);
- end;
- function TPedidosComprasCollection.Adicionar: TPedidoCompra;
- begin
- Result := TPedidoCompra(inherited Add);
- Result.Create;
- end;
- function TPedidosComprasCollection.GetItem(Index: Integer): TPedidoCompra;
- begin
- Result := TPedidoCompra(inherited GetItem(Index));
- end;
- procedure TPedidosComprasCollection.SetItem(Index: Integer; Value: TPedidoCompra);
- begin
- inherited SetItem(Index, Value);
- end;
- { TPedidoCompra }
- constructor TPedidoCompra.Create;
- begin
- fItensPedido := TPedidoCompraItemCollection.Create(Self);
- end;
- destructor TPedidoCompra.Destroy;
- begin
- fItensPedido.Free;
- inherited;
- end;
- procedure TPedidoCompra.SetItem(const Value: TPedidoCompraItemCollection);
- begin
- fItensPedido.Assign(Value);
- end;
- { TPedidoCompraItemCollection }
- constructor TPedidoCompraItemCollection.Create(AOwner: TPedidoCompra);
- begin
- inherited Create(TPedidoCompraItem);
- end;
- function TPedidoCompraItemCollection.Adicionar: TPedidoCompraItem;
- begin
- Result := TPedidoCompraItem(inherited Add);
- Result.Create;
- end;
- function TPedidoCompraItemCollection.GetItem(Index: Integer): TPedidoCompraItem;
- begin
- Result := TPedidoCompraItem(inherited GetItem(Index));
- end;
- procedure TPedidoCompraItemCollection.SetItem(Index: Integer; Value: TPedidoCompraItem);
- begin
- inherited SetItem(Index, Value);
- end;
- { TPedidoCompraItem }
- constructor TPedidoCompraItem.Create;
- begin
- end;
- destructor TPedidoCompraItem.Destroy;
- begin
- inherited;
- end;
Advertisement
Add Comment
Please, Sign In to add comment