Solved

Saving and retrieving an icon into a pic control.

Posted on 1997-08-06
8
227 Views
Last Modified: 2010-04-04
This is a very easy question.  But I'm giving a ton a points
because I need it answered.

Can someone provide a clear example of how to save and
retrieve a icon from a SQLServer database.  I'm not using
the databound controls.  I have my own query where I insert, update, and delete from a table containing a blob field.  I have a :MyIcon parameter that I am trying to fill with the blob data in the SQL statement.  

I tried to look at what the VCL does for the TDBImage control but I couldn't make heads or tails out of it.

Thanks, RM  

0
Comment
Question by:blitz051697
  • 4
  • 3
8 Comments
 
LVL 3

Expert Comment

by:mirek071497
ID: 1340708
if you familiar with stream's then try save and load icon from memory stream and then load or write this stream to a blob field.
If you have problem's or no will be another answer i write code but not today.
0
 

Author Comment

by:blitz051697
ID: 1340709
Increasing points.....
0
 

Author Comment

by:blitz051697
ID: 1340710
I'm not all that familar with streams yet.   There should be an easier way.  
0
 
LVL 3

Expert Comment

by:mirek071497
ID: 1340711
Stream's is the easiest way !!!
You must learn about stream's

This is example :
{ query work's on you'r data
  Image1 have icon for save
  Image2 receive icon from load }

{ save to data base }
procedure TForm1.Button1Click(Sender: TObject);
var
  Stream1 : TBlobStream;
begin
  Query1.Open;
  Query1.Edit;
  Stream1 := TBlobStream.Create( Query1Blob_ICON, bmReadWrite );
  Image1.Picture.Icon.SaveToStream(Stream1);
  Query1.Post;
  Stream1.Free;
  Query1.Close;
end;

{ load from data base }
procedure TForm1.Button2Click(Sender: TObject);
var
  Stream1 : TBlobStream;
begin
  Query1.Open;
  Query1.First;
  Stream1 := TBlobStream.Create( Query1Blob_ICON, bmRead );
  Image2.Picture.Icon.LoadFromStream(Stream1);
  Stream1.Free;
  Query1.Close;
end;

any questions ?
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Comment

by:blitz051697
ID: 1340712
I understand how to use the stream to pull the data into the image control.  This works fine.  However, how do I set the blob data in the SQL statement as a param in order to save it?   Your example assumes a  TBlobField object.  

For example, given this query below, how do I stream the blob data into the TheBlobData parameter?  (not a field)

INSERT INTO MYTABLE (MYBLOB) VALUES (:TheBlobData)

note : MYBLOB is a blob field in the database



0
 

Author Comment

by:blitz051697
ID: 1340713
Adjusted points to 335
0
 
LVL 3

Expert Comment

by:mirek071497
ID: 1340714
You can't do this in SQL Statement because param's is type Variant and You can't (or i don'tknow how) assign value other then : varByte,varSmallint,varInteger,varSingle,varDouble,varCurrency,varDate,varOleStrvarString,varBoolean.

The TDBiMage dont do this in SQL too.

the DBIMAGE do this :

procedure TDBImage.UpdateData(Sender: TObject);
begin
  if FDataLink.Field is TBlobField then
    with TBlobField(FDataLink.Field) do
      if Picture.Graphic is TBitmap then
        Assign(Picture.Graphic)
      else
        Clear;
end;

procedure TDBImage.SetPicture(Value: TPicture);
begin
  FPicture.Assign(Value);
end;

You can do this in some other metod and i think so my previous is good for You. Tell me Why You con't use Field's for Query, mayby i resolve this problem.
0
 
LVL 22

Accepted Solution

by:
pivar earned 330 total points
ID: 1340715
Missing some information about what SQLserver your using and what kind of field your using, this is one solution for MS SQLserver:

If your icon (MYBLOB) field is declared as an image-field, you should insert the icon as hexadecimal values. That is:

INSERT INTO MYTABLE(MYBLOB) VALUES (0x0affaabb99...

You can convert your icon data to a string of hexadecimal values and include it in your SQL statement
"Query1.SQL.Add('INSERT INTO MYTABLE(MYBLOB) VALUES('+STRINGOFHEXVALUES+')');"

I don't think that you can have larger parameters than 255 characters in Delphi 2. I'm not sure but I think this is solved in Delphi 3.

/pivar
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now