Rene Sá
Rene Sá

Reputation: 4

TFDMemTable and ListView

I created a firemonkey (XE8) application. My app reads data from XML file and populate a memTable from this. The memTable is binding a ´ListView´.

All works fine, but this process is very slow. I try using a progressbar, but when run the repeat loop, "freezes the application" and back to work when the ListView is completely filled.

How I can fix this?

Code:

procedure TForm2.layoutCatalogoClick(Sender: TObject);
var
Node: IXMLNode;
auxValor :Double;
begin
Label2.Visible := True;

mmtListaProdutos.Close;
mmtListaProdutos.CreateDataSet;
mmtListaProdutos.Open;

XMLDocument1.FileName := 'C:\dados\xml.xml';
XMLDocument1.Active := true;

Node := XMLDocument1.DocumentElement.ChildNodes.FindNode('produto');
Node.ChildNodes.First;

ProgressBar1.Max := node.ChildNodes.Count;
ProgressBar1.Value := 0;

repeat

  ProgressBar1.Value := ProgressBar1.Value + 1;
  auxValor := StrToFloat(Node.ChildNodes['valor_preco_a'].Text);

  mmtListaProdutos.Append;
  mmtListaProdutoscodigo.AsString := Node.ChildNodes['codigo'].Text;
  mmtListaProdutosdescricao.AsString := Node.ChildNodes['descricao'].Text;
  mmtListaProdutosreferencia.AsString := Node.ChildNodes['referencia'].Text;
  mmtListaProdutoscodigo_EAN.AsString := Node.ChildNodes['codigo_EAN'].Text;
  mmtListaProdutosgrupo.AsString := Node.ChildNodes['grupo'].Text;
  mmtListaProdutosfornecedor.AsString := Node.ChildNodes['fornecedor'].Text;
  mmtListaProdutosmarca.AsString := Node.ChildNodes['marca'].Text;
  mmtListaProdutosunidade.AsString := Node.ChildNodes['unidade'].Text;
  mmtListaProdutosvalidade.AsString := Node.ChildNodes['validade'].Text;
  mmtListaProdutosvalor_preco_a.AsString := Node.ChildNodes['valor_preco_a'].Text;
  mmtListaProdutosvalor_preco_b.AsString := Node.ChildNodes['valor_preco_b'].Text;
  mmtListaProdutosaltura.AsString := Node.ChildNodes['altura'].Text;
  mmtListaProdutoscomprimento.AsString := Node.ChildNodes['comprimento'].Text;
  mmtListaProdutoslargura.AsString := Node.ChildNodes['largura'].Text;
  mmtListaProdutoscodDesc.AsString := Node.ChildNodes['codigo'].Text + ' | ' + Node.ChildNodes['descricao'].Text;
  mmtListaProdutosvalorUnd.AsString := 'R$ ' + FormatFloat('#.00', auxValor) + ' / ' + Node.ChildNodes['unidade'].Text;
  mmtListaProdutosmarcaFornec.AsString := Node.ChildNodes['marca'].Text;
  mmtListaProdutos.Post;

  Node := Node.NextSibling;

until Node = nil;
mmtListaProdutos.First;

pnlListaProdutos.Visible := True;
pnlPrincipal.Visible := False;
end;

Upvotes: 1

Views: 988

Answers (1)

MartynA
MartynA

Reputation: 30715

Live Binding is not quick, especially when a multi-row GUI component like a listview is involved. And loading the data into the dataset via the listview is a particularly inefficient way of doing it.

What I'd try is disconnecting the bindings (in code) from the FDMemTable, loading the data directly into the FDMemTable, rather than into the listview, and then re-connecting the bindings to the FDMemTable.

Upvotes: 1

Related Questions