Delphi Seattle 10 popular a listview with image coming from url - Mobile

1

I'm developing a mobile system (Android and IOS) with Delphi Seattle 10 and I came across the following problem:

I need a listview and for this, I get the data via Json through a Rest server in Php.

I'm using the following components to get the data in Delphi:

  • RESTClient
  • RESTRequest
  • RESTRsponse
  • RESTResponseDataSerAdapter1
  • FDMenTable

I already receive the information correctly and display in the Listview, except for the image field because I store only the path of it in my database and then at the time of Bind in Delphi I get the following error :

EvalError in LinkFillControltoField1: Unable to cast or find converts between types string and Tbitmap.

So I ask, How do I load an image through your url in the listview mobile using something like "loadfromfile" ?

Thank you!

Diego

    
asked by anonymous 29.01.2018 / 17:55

1 answer

4

You should receive this error yourself, Bind wants to relate an image and you are delivering the path of it.

The correct thing is you save the Image itself in the database, I suggest a base64 and use a LoadFromStream or an Assign, anyway, the correct thing is to download the image and store it, to convert use: / p>

var
  vSaida   : TStringStream;
  vEntrada : TBytesStream;
begin
  vEntrada := TBytesStream.Create;
  try
    aImagem.Picture.Graphic.SaveToStream(vEntrada);
    vEntrada.Position := 0;
    vSaida := TStringStream.Create('', TEncoding.ASCII);
    try
      TNetEncoding.Base64.Encode(vEntrada, vSaida);
      Result := vSaida.DataString;
    finally
      vSaida.Free;
    end;
  finally
    vEntrada.Free;
  end;

This procedure takes a TImage and converts it to Base64, you can modify it to receive the type of image you want ...

    
30.01.2018 / 11:07