Go through TList and load TMemo with TList information

0

[TList in firemonkey mobile]

Personally, I've had a problem here for some time now.

I can not work with TList on firemonkey mobile, on specific tested until then "Android". If I compile for Win32 it works perfectly.

What I want to do is very simple. Create a list of pointers linked to product objects.

The error happens when I try to execute the procedure of loading the list into the memo, something simple, I scroll through the list and carry the memo.

// -------------------------------------------------------------------------------------------
// Objeto responsável para armazenar informações dos produtos
// -------------------------------------------------------------------------------------------
TModelProd = class
private
FPRECO: Double;
FDESCRICAO: String;
FCODPROD: Integer;
procedure SetCODPROD(const Value: Integer);
procedure SetDESCRICAO(const Value: String);
procedure SetPRECO(const Value: Double);
{ private declarations }
protected
{ protected declarations }
public
{ public declarations }
property CODPROD: Integer read FCODPROD write SetCODPROD;
property DESCRICAO: String read FDESCRICAO write SetDESCRICAO;
property PRECO: Double read FPRECO write SetPRECO;
published
{ published declarations }
end;
// -------------------------------------------------------------------------------------------

Tenho FListProd: TList;
Quero criar o ModelProd na memória e armazenar na lista.
Exemplo: FListProd.Add(ModelProd);

Abaixo segue o código utilizado.

// -------------------------------------------------------------------------------------------
unit uFrmPrincipal;

interface

uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls,
FMX.Layouts, FMX.Memo, uModelProd;

type
TFrmPrincipal = class(TForm)
btnCriarLista: TButton;
Memo1: TMemo;
Panel1: TPanel;
btnCriarProd: TButton;
btnCarregarMemo: TButton;
procedure btnCriarListaClick(Sender: TObject);
procedure btnCriarProdClick(Sender: TObject);
procedure btnCarregarMemoClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
FListProd: TList;
public
{ Public declarations }
end;

var
FrmPrincipal: TFrmPrincipal;

implementation

{$R *.fmx}

procedure TFrmPrincipal.btnCriarListaClick(Sender: TObject);
begin
if not Assigned(FListProd) then
FListProd := TList.Create;

btnCriarProd.Visible := True;
end;

procedure TFrmPrincipal.btnCriarProdClick(Sender: TObject);
Var
ModelProd: TModelProd;
iCodProd: Integer;
begin
// 1º ITEM
Inc(iCodProd);
ModelProd := TModelProd.Create;
ModelProd.CODPROD := iCodProd;
ModelProd.DESCRICAO := IntToStr(iCodProd) + '-TESTE';
ModelProd.PRECO := 20;
FListProd.Add(ModelProd);

// 2º ITEM
Inc(iCodProd);
ModelProd := TModelProd.Create;
ModelProd.CODPROD := iCodProd;
ModelProd.DESCRICAO := IntToStr(iCodProd) + '-TESTE';
ModelProd.PRECO := 20;
FListProd.Add(ModelProd);

// 3º ITEM
Inc(iCodProd);
ModelProd := TModelProd.Create;
ModelProd.CODPROD := iCodProd;
ModelProd.DESCRICAO := IntToStr(iCodProd) + '-TESTE';
ModelProd.PRECO := 20;
FListProd.Add(ModelProd);

// 4º ITEM
Inc(iCodProd);
ModelProd := TModelProd.Create;
ModelProd.CODPROD := iCodProd;
ModelProd.DESCRICAO := IntToStr(iCodProd) + '-TESTE';
ModelProd.PRECO := 20;
FListProd.Add(ModelProd);

// 5º ITEM
Inc(iCodProd);
ModelProd := TModelProd.Create;
ModelProd.CODPROD := iCodProd;
ModelProd.DESCRICAO := IntToStr(iCodProd) + '-TESTE';
ModelProd.PRECO := 20;
FListProd.Add(ModelProd);

btnCarregarMemo.Visible := True;
end;

procedure TFrmPrincipal.FormCreate(Sender: TObject);
begin
btnCriarLista.Visible := True;
btnCriarProd.Visible := False;
btnCarregarMemo.Visible := False;
end;

// O ERRO ACONTECE AQUI!!!
procedure TFrmPrincipal.btnCarregarMemoClick(Sender: TObject);
var
I: Integer;
begin
Memo1.Lines.Clear;
for I := 0 to FListProd.Count-1 do
Begin
Memo1.Lines.Add(TModelProd(FListProd.Items[i]).DESCRICAO);
End;
end;

end.
// -------------------------------------------------------------------------------

Link to source code: link I would be grateful if anyone could help me. Thanks

    
asked by anonymous 16.12.2014 / 14:33

1 answer

1

I've discovered the mystery. It replaces the System.Classes library with System.Generics.Collation , changed the TList statement.

Before it was:

FListaProd: TList

Now it's:

FListaProd: TList<TModelProd>;

Now it's working normally!

    
17.12.2014 / 11:14