Grant1842
asked on
How to load an image(Blob) from a sQlite into a timage, and a listview.
This is an Delphi MultiDevice app. Using Firedac Query and sQlite database
I am trying to load an image from a blob in an sqlite database into a ListView.
The database DDL
Here is my code
The code compiles but can not load the image from the sqlite database into the listview or a timage.
Thanks for any help .
This seems to be a problem for me.
I have attached the sorcecode.
Project4.zip
Here is the database
flatrate.db3
I am useing differnt sql here.
Differnt-Sql-Project4.zip
I am trying to load an image from a blob in an sqlite database into a ListView.
The database DDL
CREATE TABLE [Pictures](
[PicId] INT,
[UsersImage] BLOB);
Here is my code
procedure LoadFromBlob;
var
BlobStream: TStream;
begin
// FireDAC.Connected := True;
try
AccessCameraAppForm.FDQuerySelect.Open;
AccessCameraAppForm.FDQuerySelect.First;
while (not AccessCameraAppForm.viewimgquery.EOF) do
begin
// access a stream from a blob like this
BlobStream := AccessCameraAppForm.viewimgquery.CreateBlobStream
(AccessCameraAppForm.viewimgquery.FieldByName('UsersImage'),
TBlobStreamMode.bmRead);
// access a string from a field like this
if (AccessCameraAppForm.viewimgquery.FieldByName('PicId')
.AsInteger = AccessCameraAppForm.FDQuery1.FieldByName('ID').AsInteger)
then
begin
// load your blob stream data into a control
AccessCameraAppForm.viewimage.Bitmap.LoadFromStream(BlobStream);
AccessCameraAppForm.ListView2.items.Add();
BlobStream.Free;
AccessCameraAppForm.viewimgquery.Next;
end;
end;
except
on e: Exception do
begin
// ShowMessage(e.Message);
end;
end;
// FireDAC.Connected := False;
end;
I am useing the live bindings to bind the querys image to the listviews item.image2The code compiles but can not load the image from the sqlite database into the listview or a timage.
Thanks for any help .
This seems to be a problem for me.
I have attached the sorcecode.
Project4.zip
Here is the database
flatrate.db3
I am useing differnt sql here.
Differnt-Sql-Project4.zip
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
This is for accessing newly created ListViewItem. With them you can:
- change label:
itm.Text := ...
- set image index:
itm.ImageIndex := ...
and so on...
- change label:
itm.Text := ...
- set image index:
itm.ImageIndex := ...
and so on...
why are you mixing procedural and object oriented code ?
that's just making your life difficult
if you create a second instance of TForm4 named formXYZ like:
that procedure won't work.
but ... correctly :
and then you don't need to use Form4, which possibly doesn't exist:
sample:
that's just making your life difficult
if you create a second instance of TForm4 named formXYZ like:
formXYZ := TForm4.create(application);
that procedure won't work.
but ... correctly :
private
{ Private declarations }
procedure LoadFromBlob;
public
{ Public declarations }
end;
var
Form4: TForm4;
implementation
{$R *.fmx}
procedure TForm4.LoadFromBlob;
and then you don't need to use Form4, which possibly doesn't exist:
sample:
if viewimgquery.FieldByName('PicId').AsInteger = FDQuery1.FieldByName('ID').AsInteger then
that was just to say something about the wrong code
and yes ... confusing, sinisa got that right :)
and yes ... confusing, sinisa got that right :)
ASKER
What does Itm equal
itm := form4.ListView1.items.Add(