Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: TFDQuery Blob/image field show in a ListView



Permlink Replies: 3 - Last Post: Sep 27, 2017 10:34 AM Last Post By: Jeff Overcash (...
Jose Anchieta C...

Posts: 3
Registered: 10/9/14
TFDQuery Blob/image field show in a ListView
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 26, 2017 6:43 PM
Hello!

How to get blob field, FireDac (SQLite) and show in a ListView, using Firemonkey ?
Here is my code.
The image does not display..

procedure TForm1.Button1Click(Sender: TObject);
var ItemAdd: TlistViewItem;
BLOB: TBlobField;
BS: TStream;
begin
DM.QryProduto.Active := True;

ListView1.Items.Clear;
ListView1.BeginUpdate;

DM.QryProduto.First;

while not DM.QryProduto.Eof do
begin
ItemAdd := ListView1.Items.Add;
BLOB := DM.QryProduto.FieldByName('foto') as TBlobField;

ItemAdd.Bitmap.Assign(BLOB);
ItemAdd.Text := DM.QryProdutodescricao.AsString;
DM.QryProduto.Next;
end;

ListView1.EndUpdate;
end;

Thank you!

Jeff Overcash (...

Posts: 1,529
Registered: 9/23/99
Re: TFDQuery Blob/image field show in a ListView
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 26, 2017 8:10 PM   in response to: Jose Anchieta C... in response to: Jose Anchieta C...
Jose Anchieta Carvalho wrote:
Hello!

How to get blob field, FireDac (SQLite) and show in a ListView, using Firemonkey ?
Here is my code.
The image does not display..

procedure TForm1.Button1Click(Sender: TObject);
var ItemAdd: TlistViewItem;
BLOB: TBlobField;
BS: TStream;
begin
DM.QryProduto.Active := True;

ListView1.Items.Clear;
ListView1.BeginUpdate;

DM.QryProduto.First;

while not DM.QryProduto.Eof do
begin
ItemAdd := ListView1.Items.Add;
BLOB := DM.QryProduto.FieldByName('foto') as TBlobField;

ItemAdd.Bitmap.Assign(BLOB);
ItemAdd.Text := DM.QryProdutodescricao.AsString;
DM.QryProduto.Next;
end;

ListView1.EndUpdate;
end;

Thank you!


Try getting a TBlobStream instead and do load from stream for your bitmap.

--
Jeff Overcash (TeamB)
(Please do not email me directly unless asked. Thank You)
Learning is finding out what you already know. Doing is demonstrating that you
know it. Teaching is reminding others that they know it as well as you. We are
all leaners, doers, teachers. (R Bach)
Dave Nottage

Posts: 1,850
Registered: 1/7/00
Re: TFDQuery Blob/image field show in a ListView
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 27, 2017 2:01 AM   in response to: Jose Anchieta C... in response to: Jose Anchieta C...
Jose Anchieta Carvalho wrote:

BLOB := DM.QryProduto.FieldByName('foto') as TBlobField;

ItemAdd.Bitmap.Assign(BLOB);

You can use a stream, e.g:

var
  LStream: TStream;
 
...
 
  LStream := TMemoryStream.Create;
  try
    BLOB.SaveToStream(LStream);
    LStream.Position := 0;
    ItemAdd.Bitmap.LoadFromStream(LStream);
  finally
    LStream.Free;
  end;


--
Dave Nottage [MVP, TeamB]
Find hints, tips and tricks at Delphi Worlds blog: http://www.delphiworlds.com
Jeff Overcash (...

Posts: 1,529
Registered: 9/23/99
Re: TFDQuery Blob/image field show in a ListView
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 27, 2017 10:34 AM   in response to: Dave Nottage in response to: Dave Nottage
Dave Nottage <Dave Nottage (TeamB) wrote:
Jose Anchieta Carvalho wrote:

BLOB := DM.QryProduto.FieldByName('foto') as TBlobField;

ItemAdd.Bitmap.Assign(BLOB);

You can use a stream, e.g:

var
  LStream: TStream;
 
...
 
  LStream := TMemoryStream.Create;
  try
    BLOB.SaveToStream(LStream);
    LStream.Position := 0;
    ItemAdd.Bitmap.LoadFromStream(LStream);
  finally
    LStream.Free;
  end;


That can be simplified down

   LStream := DM.QryProduto.CreateBlobStream(DM.QryProduto.FieldByName('foto'), 
bmRead);
   try
     ItemAdd.Bitmap.LoadFromStream(LStream);
   finally
     LStream.Free;
   end;

--
Jeff Overcash (TeamB)
(Please do not email me directly unless asked. Thank You)
Learning is finding out what you already know. Doing is demonstrating that you
know it. Teaching is reminding others that they know it as well as you. We are
all leaners, doers, teachers. (R Bach)

Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02