Delphi _How to pass data to a property of type record array

0
 unit Exemplo;

interface
uses Classes, 
     SysUtils, typinfo;

const 

type 

  {TRecordRateio}
  TRecordRateio =       Record
    IdContaCorrente   : Integer;
    CodBanco          : String;
    Agencia           : String;
    DVAgencia         : String;
    ContaCorrente     : String;
    DVContaCorrente   : String;
    DVAgenciaConta    : String;
    NomeBeneficiario  : String;
    CodRateio         : String;
    EPercentual       : String;
    ValorRateio       : Currency;
    FloatingRateio    : String;
    DataCredito       : TDateTime;
 end;

 TArrayOfRateio =  Array of TRecordRateio;


  TTeste = class(TComponent)
  private
    fRateio        : TArrayOfRateio;
    function GetRateio(AIndex: Integer): TArrayOfRateio;
    procedure SetRateio(AIndex: Integer; const Value: TArrayOfRateio);

  public
    constructor Create( AOwner : TComponent ) ; override ;
    destructor Destroy; override;
    property Rateio[AIndex : Integer] : TArrayOfRateio read GetRateio Write SetRateio; default;  
  published
    property Nome         : String read fNome  write fNome;
  end;


implementation

Uses Forms, Math, dateutils, strutils;


constructor TTeste.Create( AOwner : TComponent );
begin
   inherited Create(AOwner);
   fNome   := '';   
end;

destructor TTeste.Destroy;
begin
  inherited;
end;


function TTeste.GetRateio(AIndex: Integer): TArrayOfRateio;
begin
  Result[AIndex].IdContaCorrente  := Self.fRateio[AIndex].IdContaCorrente;
  Result[AIndex].CodBanco         := Self.fRateio[AIndex].CodBanco;
  Result[AIndex].Agencia          := Self.fRateio[AIndex].Agencia;
  Result[AIndex].DVAgencia        := Self.fRateio[AIndex].DVAgencia;
  Result[AIndex].ContaCorrente    := Self.fRateio[AIndex].ContaCorrente;
  Result[AIndex].DVContaCorrente  := Self.fRateio[AIndex].DVContaCorrente;
  Result[AIndex].DVAgenciaConta   := Self.fRateio[AIndex].DVAgenciaConta;
  Result[AIndex].NomeBeneficiario := Self.fRateio[AIndex].NomeBeneficiario;
  Result[AIndex].CodRateio        := Self.fRateio[AIndex].CodRateio;
  Result[AIndex].FloatingRateio   := Self.fRateio[AIndex].FloatingRateio;
  Result[AIndex].EPercentual      := Self.fRateio[AIndex].EPercentual;
  Result[AIndex].ValorRateio      := Self.fRateio[AIndex].ValorRateio;
  Result[AIndex].DataCredito      := Self.fRateio[AIndex].DataCredito;     
end;

procedure TTeste.SetRateio(AIndex: Integer;
  const Value: TArrayOfRateio);
begin
  frateio[AIndex].Idcontacorrente  := Value[AIndex].IdContaCorrente;
  fRateio[AIndex].CodBanco         := Value[AIndex].CodBanco;
  fRateio[AIndex].Agencia          := Value[AIndex].Agencia;
  fRateio[AIndex].DVAgencia        := Value[AIndex].DVAgencia;
  fRateio[AIndex].ContaCorrente    := Value[AIndex].ContaCorrente;
  fRateio[AIndex].DVContaCorrente  := Value[AIndex].DVContaCorrente;
  fRateio[AIndex].DVAgenciaConta   := Value[AIndex].DVAgenciaConta;
  fRateio[AIndex].NomeBeneficiario := Value[AIndex].NomeBeneficiario;
  fRateio[AIndex].CodRateio        := Value[AIndex].CodRateio;
  fRateio[AIndex].FloatingRateio   := Value[AIndex].FloatingRateio;
  fRateio[AIndex].EPercentual      := Value[AIndex].EPercentual;
  fRateio[AIndex].ValorRateio      := Value[AIndex].ValorRateio;
  fRateio[AIndex].DataCredito      := Value[AIndex].DataCredito ;
end;

How to access the Test.Rateio property above?

    
asked by anonymous 18.12.2017 / 01:54

1 answer

0

I think you've made the mistake of setting the TArrayOfRateio type instead of TRecordRateio.

If you change to

 property Rateio[AIndex : Integer] : TRecordRateio read GetRateio Write SetRateio; default; 

and the respective Set and Get to receive and send a TRecordRateio, you have the record accessible.

    
18.12.2017 / 22:30