How popular Listview pictures with Ascync android firemonkey?

Asked

Viewed 1,326 times

1

With popular the Listview with the function below, but popular images cause small crashes, I searched a little and found suggestions of using Threads with Async, but I couldn’t apply to my project.

My question is: How to popular the images in a fluid way, first populating the texts, and the images as they are loaded?

ListView1.BeginUpdate;
while not qrycliente.Eof do
begin
  ////carrega imagem
  stm:= qrycliente.CreateBlobStream(qrycliente.FieldByName('IMAGEM'), bmRead);

  if stm.Size > 0 then
  begin

    try
      img := TBitmap.Create;
      img.LoadFromStream(Stm);
      try
        rr_imagem.Fill.Bitmap.Bitmap.Assign(img);
        inicial:= '';
      except
        inicial:= Copy(qrycliente.FieldByName('CLIENTE').AsString, 0, 1);
      end;
    finally
      Stm.Free;
      img.Free;
    end;

  end
  else
  begin
    inicial:= Copy(qrycliente.FieldByName('CLIENTE').AsString, 0, 1);
  end;
  ////

  LItem := ListView1.Items.Add;
  LItem.Detail := IntToStr(qrycliente.FieldByName('ID').AsInteger);
  LItem.Data['nome']:= qrycliente.FieldByName('CLIENTE').AsString;
  LItem.Data['fantasia']:= qrycliente.FieldByName('FANTASIA').AsString;

  LItem.Data['endereco']:= qrycliente.FieldByName('ENDERECO').AsString+','+
                           qrycliente.FieldByName('NUMERO').AsString;

  LItem.Data['bairro_cidade']:= qrycliente.FieldByName('BAIRRO').AsString+','+
                                qrycliente.FieldByName('CIDADE').AsString;

  LItem.Data['telefone']:= qrycliente.FieldByName('TELEFONE').AsString+' / '+
                           qrycliente.FieldByName('TELEFONE2').AsString+' / '+
                           qrycliente.FieldByName('CELULAR').AsString;

  LItem.Data['letra']:= inicial;

  LItem.Data['imagem']:= rr_imagem.MakeScreenshot;

  qrycliente.Next;
end;
ListView1.EndUpdate;
No answers

Browser other questions tagged

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