0
I am inciante in Mobile and I am in the following situation: have 3 listview that receives data via Rest from a PHP site
using restClient, Restrequest and restResponse... data gets certificate, popula alistvew all correctly, compiles also everything normal.... the problem comes next.....
in Rest has an image field (jpg,png) only the image url, use this function to convert the image to Bitmap
function TfrmPrincipal.LerImage(url: string): TBitmap;
var
strm : TmemoryStream;
begin
strm := TMemoryStream.Create;
try
http.Get(url,strm);
strm.Position := 0;
Result := TBitmap.Create;
result.Width := 100;
result.Height := 50;
result.LoadFromStream(strm);
finally
strm.Free;
end;
end;
however when I put in listview this image the application hangs (stop responding..... use this way in listview
procedure TFrmprincipal.ExecuteREST(aList: TListview; aArray: string);
var
obj : TjsonObject;
Item : TlistviewItem;
lResult : TjsonArray;
strm : TMemoryStream;
begin
lResult := REST(aArray);
TThread.CreateAnonymousThread(
procedure
var
i: Integer;
begin
for i:= 0 to lresult.Count-1 do
begin
TThread.Synchronize(TThread.CurrentThread, procedure()
begin
obj := lResult.Items[i] as TJSONObject;
Item := aList.Items.Add;
item.text := obj.GetValue('nome').Value;
if (obj.GetValue('logo').ToString <> 'null') then
Item.bitmap := LerImage(''+PathUrl+'/images/empresas/'+obj.GetValue('logo').Value)
else
Item.bitmap := LerImage(''+PathUrl+'/images/empresas/semimagem.png');
end);
end
end).Start;
end;
The detail is if put only 2 listview works correctly... but if you put a button to pull the other listview hangs also.... I’ve tried it in many ways, with Ttask, with Thread and without Thread, with Synchronize, with Queue and nothing.....
Someone gives me a light how to solve this??
In fact at first glance it is doing everything right.... no clue on the exact line where it hangs?
– Tiago Rodrigues
if I put image item.bitmap, this image comes from a website... if I place the three listview hangs, if puts two or one, opens normal.
– Geraldo Lacerda