-
Постов
2 -
Зарегистрирован
-
Посещение
Сообщения, опубликованные Osvaldo G. Da Cruz Júnior
-
-
Em tempo de execução, também pode utilizar o evento: UpdateObjects:
procedure TMainForm.LIstView1UpdateObjects(const Sender: TObject; const AItem: TListViewItem);
var
URL_Foto: String;
Foto: TListItemImage;
Strm: TMemoryStream;
TmpImagem: TImage;
Http: TiDHTTP;
myThread: TThread;
begin
Foto := TListItemImage(AItem.View.FindDrawable('FOTO'));
URL_Foto := TListItemText(AItem.View.FindDrawable('URL_FOTO')).Text;
TListItemText(AItem.View.FindDrawable('URL_FOTO')).Visible := False;
if (not URL_Foto.IsEmpty ) and (Foto <> nil) and (Foto.Bitmap = nil) then
begin
URL_Foto := 'http://www.SEUDOMINIO.com.br/imagens/' + URL_Foto;
myThread := TThread.CreateAnonymousThread( procedure ()
begin
Strm := TMemoryStream.Create;
Http := TiDHTTP.Create(Self);
TmpImagem := TImage.Create(nil);
livAnuncioCaminhao.BeginUpdate;
try
Http.Get(URL_FOTO, Strm);
if (Strm.Size > 0) then
begin
Strm.Position := 0;
TThread.Synchronize(myThread, procedure ()
begin
TmpImagem.Bitmap.LoadFromStream(Strm);
Foto.OwnsBitmap := False;
Foto.Bitmap := nil;
Foto.Bitmap := TmpImagem.Bitmap;
end);;
end;
finally
Strm.Free;
Http.Free;
//Assim dá access violation
//TmpImagem.Free;
livAnuncioCaminhao.EndUpdate;
end;
end);
myThread.start();
end;
end;
[TListView] Как загрузить картинку в итем TListView из TImageList?
в TImageList - с XE8
Опубликовано
Correção:
Substituir: livAnuncioCaminhao.BeginUpdate e livAnuncioCaminhao.EndUpdate
Para: ListView1.BeginUpdate e ListView1.EndUpdate
procedure TMainForm.LIstView1UpdateObjects(const Sender: TObject; const AItem: TListViewItem); var URL_Foto: String; Foto: TListItemImage; Strm: TMemoryStream; TmpImagem: TImage; Http: TiDHTTP; myThread: TThread; begin Foto := TListItemImage(AItem.View.FindDrawable('FOTO')); URL_Foto := TListItemText(AItem.View.FindDrawable('URL_FOTO')).Text; TListItemText(AItem.View.FindDrawable('URL_FOTO')).Visible := False; if (not URL_Foto.IsEmpty ) and (Foto <> nil) and (Foto.Bitmap = nil) then begin URL_Foto := 'http://www.SEUDOMINIO.com.br/imagens/' + URL_Foto; myThread := TThread.CreateAnonymousThread( procedure () begin Strm := TMemoryStream.Create; Http := TiDHTTP.Create(Self); TmpImagem := TImage.Create(nil); ListView1.BeginUpdate; try Http.Get(URL_FOTO, Strm); if (Strm.Size > 0) then begin Strm.Position := 0; TThread.Synchronize(myThread, procedure () begin TmpImagem.Bitmap.LoadFromStream(Strm); Foto.OwnsBitmap := False; Foto.Bitmap := nil; Foto.Bitmap := TmpImagem.Bitmap; end);; end; finally Strm.Free; Http.Free; //Assim dá access violation //TmpImagem.Free; ListView1.EndUpdate; end; end); myThread.start(); end; end;