android - how to add images from URL to ListBox -


i want load images url list in listbox items, code retrieve urls

var  ljsonarray : tjsonarray;  lentity: tbackendentityvalue;  : integer; begin  try   ljsonarray := tjsonarray.create;   backendstorage1.storage.queryobjects('list', [], ljsonarray);    := 0 ljsonarray.count-1     begin      listbox4.items.add (ljsonarray.items[i].getvalue<string>('pictures'));     end;     ljsonarray.free;  end;  end; 

update 1

procedure tform1.button1click(sender: tobject); var  lbitem    : tlistboxitem;  i: integer;  http : tidhttp;  stream : tmemorystream; begin  http := tidhttp.create(nil); try  := 0 listbox1.items.count-1   begin    lbitem := tlistboxitem.create(nil);    lbitem.parent := listbox2;    lbitem.height := 100;    stream := tmemorystream.create;    http.get(listbox1.items.strings[i], stream);    lbitem.itemdata.bitmap.loadfromstream(stream);    end;    stream.free;   http.free; end; end; 

i tried loading pictures in listbox, however, there items added without pictures !

after tidhttp.get() downloads image tmemorystream, need seek stream position 0 before it, loading bitmap. , add try..except block handle download errors.

also, should using second try..finally block freeing tmemorystream.

procedure tform1.button1click(sender: tobject); var  lbitem    : tlistboxitem;  i: integer;  http : tidhttp;  stream : tmemorystream; begin  http := tidhttp.create(nil); try  := 0 listbox1.items.count-1   begin    lbitem := tlistboxitem.create(nil);    lbitem.parent := listbox2;    lbitem.height := 100;    stream := tmemorystream.create;    try      try        http.get(listbox1.items.strings[i], stream);        stream.position := 0; // <-- add        lbitem.itemdata.bitmap.loadfromstream(stream);      except        // else      end;         stream.free;    end;   end;    http.free;  end; end; 

Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -

java - Digest auth with Spring Security using javaconfig -