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

Asked

Viewed 684 times

1

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

I need to popular a listview and for that, I receive the data via Json through a Rest server in Php.

I am using the components below to receive the data in Delphi:

  • Restcliente
  • Restrequest
  • Restraint
  • Restresponsedataseradapter1
  • Fdmentable

I already receive the information correctly and display in Listview, except for the field image why I only store her path in my database and then when it’s time to perform Bind in Delphi I get the following error:

Evalerror in Linkfillcontroltofield1: Unable to cast or find converters between types string and Tbitmap.

So I ask you: How do I upload an image through its url in listview mobile using something like "loadfromfile"?

thank you!

Diego

1 answer

4


You should get this error even, Bind wants to relate an image and you are handing her way.

The correct is you save the Image itself in the database, I suggest a base64 and use a Loadfromstream or Assign, anyway, the correct is to download the image and store it, to convert use:

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 to Base64, you can modify it to receive the type of image you want...

  • thanks for the help and response! hugs!

Browser other questions tagged

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