FNCTableView TObject Record example


FMXTableView had a lot of extra properties that I used in order to save data like: Tag, TagString, TagFloat, DataBoolean, DataString, DataValue, Description, Caption... and so on.

I used such properties in order to save field values from a RemoteDB components.

Now in FNCTableView the number of different extra properties are limited, can you please give me an example of how to use a TRecord type as TObject so I can use it properly in every item of the TableView?

By example how to use the next TRecord type
TCustomer = Record
firstName : string[20];
lastName : string[20];
address1 : string[100];
address2 : string[100];
address3 : string[100];
city : string[20];
postCode : string[8];

I mean how to pass such TCustomer into FNCTableView.Item.DataObject, where "X" is a dinamic integer value, furthermore when I need to clear items do I need to destroy every Tcustomer type?


If TCustomer is a Record type, you don't need to destroy it. But if it's a class type, then you will indeed need to destroy it. The proper way to implement this is to keep track of your records in a TObjectList, and then destroy it which will clear memory. And then assign a customer reference to the DataObject to use it in the tableview.

Thanks for clarification, you did not gave me the example of how to use the record type, however I did my research on the web, so I will share the code in case another tms customer want it.


 // Creamos el tipo de registro para el Cliente
      pDatosClientes = ^TDatosClientes;
      TDatosClientes = record
           ID: Integer;
           nombre: String;
           domicilio: String;
           limiteCredito: Double;
           precioVenta: Integer;
           email: String;
           puntos: Double;
           diasCredito: Integer;
           retencionIVA: Double;
           retencionISR: Double;

Use for store into a FNCtableviewitem as DataObject

DatoCliente: pDatosClientes;
// Creamos los datos extra del cliente
DatoCliente^.ID := ConsultaClientes.FieldByName('ID').AsInteger;
DatoCliente^.nombre := ConsultaClientes.FieldByName('Nombre').AsString;
DatoCliente^.domicilio := ConsultaClientes.FieldByName('Domicilio').AsString;
DatoCliente^.limiteCredito := ConsultaClientes.FieldByName('limiteCredito').AsFloat;
DatoCliente^.precioVenta := ConsultaClientes.FieldByName('precioVenta').AsInteger;
DatoCliente^.email := ConsultaClientes.FieldByName('Email').AsString;
DatoCliente^.puntos := ConsultaClientes.FieldByName('puntos').AsFloat;
DatoCliente^.diasCredito := ConsultaClientes.FieldByName('diasCredito').AsInteger;
DatoCliente^.retencionIVA := ConsultaClientes.FieldByName('retencionISR').AsFloat;
DatoCliente^.retencionISR := ConsultaClientes.FieldByName('retencionISR').AsFloat;

// Asociamos los valores al Objeto
FNCTableView.Item.DataObject := TObject(DatoCliente);

Use for read from a FNCtableviewitem as DataObject

DatoCliente: pDatosClientes;
// Obtenemos los valores de regreso almacenados como objetos
DatoCliente := pDatosClientes(FNCTableView.Item.DataObject);

PrecioVentaDefault := DatoCliente^.precioVenta;

Use for modify to a FNCtableviewitem as DataObject

pDatosClientes(FNCTableView.Item.DataObject)^.puntos := XXXXX;