Home Cannot assign value to object with array of records
Reply: 0

Cannot assign value to object with array of records

user1656
1#
user1656 Published in May 25, 2018, 9:04 am

I'm writing a simple object that contain array of records. Just like invoice.(ID,date,customer name and array of records about the items).

type
  Trows = record
  private
    Fcode: string;
    Qty: Double;
    cena: Currency;
    procedure Setcode(const value: string);
  public
    property code: string read Fcode write SetCode;
  end;

  Tcart = class(TObject)
  private
    Frow: array of Trows;
    function  Getrow(Index: Integer): Trows;
    procedure Setrow(Index: Integer; const Value: Trows);
  public
    ID: integer;
    CustName: string;
    Suma: currency;
    Payed: boolean;
    constructor Create(const Num: Integer);
    destructor Destroy;
    function carttostr: string;
    procedure setcode(Index: integer;val: string);
    property Row[Index: Integer]: Trows read Getrow write setrow;
  end;

Everything seems fine since I'm trying to change value of one record. I have found 3 ways to do it. First, and second worked ok, but I'd like to simplify the code modifying the value of this record like this:

cart.row[0].code:='333';

but it doesn't work.

What am I'm missing?

Here is the code:

procedure TForm1.Button1Click(Sender: TObject);
var
  Arows: Trows;
begin
  Cart:=Tcart.Create(0);
  cart.custName:='Customer 1';
  cart.Suma:=5.55;
  cart.Payed:=false;
  Arows.code:='123';
  cart.setrow(0,Arows);  // this way working
  cart.setcode(0,'333');   // this way also working
  cart.row[0].code:='555';      //this way doesn''t change value. How to make it work?
  memo1.Lines.Text:=cart.carttostr;
end;
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.405986 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO