I have a question regarding loading images in Delphi. My average image is 47kb, when I show it on ListView the application almost comes to lock for the time of the answer.
Images are stored directly in the database with the type pre-defined blob.
My question is this, the loading delay is related with the way I'm bringing the data or is it a ListView problem?
What is the best way to do this loading? If I store the images in a folder on the server and display them through the URL will I have a better performance?
Here is the snippet of code I read and I wrap it to the ListView:
{$REGION 'Lista Produto'}
TThread.CreateAnonymousThread(
procedure()
begin
TThread.Synchronize(TThread.CurrentThread,
procedure()
begin
dm.UniQuery1.sql.text := 'SELECT pro_id, pro_ds, pro_img, pro_preco '+
'FROM produto WHERE '+
' pro_ds like '+q('%'+edDescricao.Text+'%')+
' AND pro_fabricante_id like '+q(IfThen((edFabricante.Text<>''),auxFabricante,'%'))+
' AND pro_secao like '+q(IfThen((edSecao.Text<>''),auxSecao,'%'))+
' AND pro_merc_id like '+q(IfThen((edMercado.Text<>''),auxMercado,'%'))+
' ORDER BY pro_id DESC';
dm.UniQuery1.Open;
try
ListView1.BeginUpdate;
ListView1.Items.Clear;
S := TMemoryStream.Create();
while not dm.UniQuery1.Eof do
begin
LItem := ListView1.Items.add;
LItem.Text := dm.UniQuery1.FieldByName('pro_ds').AsString;
LItem.Data[TMultiDetailAppearanceNames.Detail1] := dm.UniQuery1.FieldByName('pro_ds').AsString;
LItem.Data[TMultiDetailAppearanceNames.Detail2] := 'R$ '+
FormatFloat('###,###0.00', dm.UniQuery1.FieldByName('pro_preco').AsCurrency);
TblobField(dm.UniQuery1.FieldByName('pro_img')).SaveToStream(S);
s.Position := 0;
imgAux.Bitmap.LoadFromStream(S);
LItem.Bitmap := imgAux.Bitmap;
dm.UniQuery1.Next;
end;
Application.ProcessMessages;
ListView1.EndUpdate;
except
on E: Exception do
ShowMessage('Erro: ' + E.Message);
end;
Application.ProcessMessages;
end);
TThread.Synchronize(TThread.CurrentThread,
procedure()
begin
end);
end).Start;
{$ENDREGION}