Advertisement
jacknpoe

Exemplos de set e get de arrays em Delphi

Feb 29th, 2024 (edited)
972
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.78 KB | Source Code | 0 0
  1. unit Classe;
  2.  
  3. interface
  4.  
  5. Type
  6. TClasse = class
  7.   private
  8.     fQuantidade: integer;
  9.     fPagamentos: array of integer;
  10.     fPesos: array of double;
  11.   public
  12.     function GetQuantidade: integer;
  13.     procedure SetQuantidade(valor: integer);
  14.     function GetPagamentos(indice: integer): integer;
  15.     procedure SetPagamentos(indice: integer; valor: integer);
  16.     function GetPesos(indice: integer): double;
  17.     procedure SetPesos(indice: integer; valor: double);
  18.   published
  19.     property Quantidade: integer read GetQuantidade write SetQuantidade;
  20.     property Pagamentos[indice: integer]: integer read GetPagamentos write SetPagamentos;
  21.     property Pesos[indice: integer]: double read GetPesos write SetPesos;
  22. end;
  23.  
  24. implementation
  25.  
  26. function TClasse.GetQuantidade: integer;
  27. begin
  28.   result := fQuantidade;
  29. end;
  30.  
  31. procedure TClasse.SetQuantidade(valor: integer);
  32. begin
  33.   if (valor < 0) then
  34.   begin
  35.     exit;
  36.   end;
  37.   fQuantidade := valor;
  38.   SetLength(fPagamentos, valor);
  39.   SetLength(fPesos, valor);
  40. end;
  41.  
  42. function TClasse.GetPagamentos(indice: integer): integer;
  43. begin
  44.   if (indice < 0) or (indice >= fQuantidade) then
  45.   begin
  46.     result := 0;
  47.     exit;
  48.   end;
  49.   result := fPagamentos[indice];
  50. end;
  51.  
  52. procedure TClasse.SetPagamentos(indice: integer; valor: integer);
  53. begin
  54.   if (indice < 0) or (indice >= fQuantidade) then
  55.   begin
  56.     exit;
  57.   end;
  58.   fPagamentos[indice] := valor;
  59. end;
  60.  
  61. function TClasse.GetPesos(indice: integer): double;
  62. begin
  63.   if (indice < 0) or (indice >= fQuantidade) then
  64.   begin
  65.     result := 0.0;
  66.     exit;
  67.   end;
  68.   result := fPesos[indice];
  69. end;
  70.  
  71. procedure TClasse.SetPesos(indice: integer; valor: double);
  72. begin
  73.   if (indice < 0) or (indice >= fQuantidade) then
  74.   begin
  75.     exit;
  76.   end;
  77.   fPesos[indice] := valor;
  78. end;
  79.  
  80. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement