blitz051697
asked on
Saving and retrieving an icon into a pic control.
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
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
ASKER
Increasing points.....
ASKER
I'm not all that familar with streams yet. There should be an easier way.
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.SaveTo Stream(Str eam1);
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.LoadFr omStream(S tream1);
Stream1.Free;
Query1.Close;
end;
any questions ?
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
var
Stream1 : TBlobStream;
begin
Query1.Open;
Query1.Edit;
Stream1 := TBlobStream.Create( Query1Blob_ICON, bmReadWrite );
Image1.Picture.Icon.SaveTo
Query1.Post;
Stream1.Free;
Query1.Close;
end;
{ load from data base }
procedure TForm1.Button2Click(Sender
var
Stream1 : TBlobStream;
begin
Query1.Open;
Query1.First;
Stream1 := TBlobStream.Create( Query1Blob_ICON, bmRead );
Image2.Picture.Icon.LoadFr
Stream1.Free;
Query1.Close;
end;
any questions ?
ASKER
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
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
ASKER
Adjusted points to 335
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,varInt eger,varSi ngle,varDo uble,varCu rrency,var Date,varOl eStrvarStr ing,varBoo lean.
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.
The TDBiMage dont do this in SQL too.
the DBIMAGE do this :
procedure TDBImage.UpdateData(Sender
begin
if FDataLink.Field is TBlobField then
with TBlobField(FDataLink.Field
if Picture.Graphic is TBitmap then
Assign(Picture.Graphic)
else
Clear;
end;
procedure TDBImage.SetPicture(Value:
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If you have problem's or no will be another answer i write code but not today.