Delphi _How to pass data to a record array type property

Asked

Viewed 975 times

-1

 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.Apportioning property above?

  • It is not clear what you want. If Teste is a variable of the type TTeste and just want to access, it would be something like Teste.Rateio[0].Agencia. Are you having any problems with this code? Which?

1 answer

0

I think you made the mistake of putting the Tarrayofrateio type of power 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 Trecordappy, you will have the registration accessible.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.