Make sure the field type is TBlobField and nothing is data bound to that field. We use this code to store PDFs, TIFs, ZIPs, etc into SQL Server. I just whipped this together quickly as a test:
program Project7; {$APPTYPE CONSOLE} uses Classes, SysUtils, DBClient, DB, ComOBJ; var cds: TClientDataset; procedure LoadImage(fld: TField; const sFile: String); var fs: TFileStream; begin fs := TFileStream.Create(sFile, fmOpenRead); try fs.Position := 0; TBlobField(fld).LoadFromStream(fs); finally fs.free; end; end; begin try cds := TClientDataset.Create(nil); cds.FieldDefs.Add('ID', ftGUID, 38, True); cds.FieldDefs.Add('File', ftString, 512); cds.FieldDefs.Add('Data', ftBlob); cds.CreateDataSet; cds.Open; cds.LogChanges := False; cds.Insert; cds.Fields[0].AsString := CreateClassID; cds.Fields[1].AsString := 'c:\test.gif'; LoadImage(cds.Fields[2], cds.Fields[1].AsString); cds.Post; cds.SaveToFile('c:\test.cds'); cds.Close; cds.Free; except on E:Exception do begin Writeln(E.Classname, ': ', E.Message); ReadLn; end; end; end. On Wed, Mar 16, 2011 at 1:36 AM, SoftTech <mi...@softtechks.com> wrote: > Greetings Cameron, > > Using Delphi 2010, I checked the help file and it states that TGifImage is > part of the GifImg unit which is in my Interface uses clause already. > > When you say "This is a guess of sorts but I think if you load TGifImage > into your project this error might go away for the Graphic field.", how do I > load TGifImage into my project? > > Anyway, since I'm not sure what you meant by that, I did try adding your > code to a button click event as shown below, and it is giving me the same > error "Bitmap image is not valid". > > procedure TForm1.Button1Click(Sender: TObject); > > procedure LoadImage(fld: TBlobField; const sFile: String); > var > fs: TFileStream; > begin > fs := TFileStream.Create(sFile, fmOpenRead); > try > fs.Position := 0; > fld.LoadFromStream(fs); > finally > fs.free; > end; > end; > > begin > with OpenPictureDialog1 do > begin > if Execute() then > begin > cdsWeatherForcast.Edit; > > // cdsWeatherForcastIMAGE.LoadFromFile(OpenPictureDialog1.FileName); > LoadImage(cdsWeatherForcastIMAGE, OpenPictureDialog1.FileName); > > cdsWeatherForcast.Post; > end; > end; > > end; > I know it is something I'm doing wrong, so if you see what it is please > let me know. This is really rather frustrating to me... > > Thanks again for your help. > Mike > > > ----- Original Message ----- > *From:* Cameron Cole <came...@cameroncole.com> > *To:* Delphi-Talk Discussion List <delphi-talk@elists.org> > *Cc:* SoftTech <mi...@softtechks.com> > *Sent:* Tuesday, March 15, 2011 4:42 PM > *Subject:* Re: Storing a 32x32 gif image in a TClientDataset > > This is a guess of sorts but I think if you load TGifImage into your > project this error might go away for the Graphic field. > > I generally use a FileStream to stream the file into the field like this: > > procedure LoadImage(fld: TBlobField; const sFile: String); > var > fs: TFileStream; > begin > fs := TFileStream.Create(sFile, fmOpenRead); > try > fs.Position := 0; > fld.LoadFromStream(fs); > finally > fs.free; > end; > end; > > > On Tue, Mar 15, 2011 at 5:00 PM, SoftTech <mi...@softtechks.com> wrote: > >> Greetings All, >> >> I'm experimenting with my first Web Service by creating a program to read >> weather info off the internet. >> >> I have an in-memory dataset (TClientDataset) that I tried adding either a >> TGraphicField or a TBlobField to for storing a 32x32 gif image. >> >> During an append operation I'm trying to use the following code to add a >> gif to this TCleintDataset >> >> cdsWeatherForcastIMAGE.LoadFromFile('C:\WeatherServices WSDL Web Service >> Example\weather icons\' + cdsWeatherInfoFILENAME.AsString); >> >> It errors out with "Bitmap image is not valid" as soon as that line is >> fired. >> >> Any ideas what I may be doing wrong? >> >> Thanks, >> Mike >> >> >> >> __________________________________________________ >> Delphi-Talk mailing list -> Delphi-Talk@elists.org >> http://lists.elists.org/cgi-bin/mailman/listinfo/delphi-talk >> > > > -- > MailScanner Virus/Spam/Malware: PASS (GZ) > > __________________________________________________ Delphi-Talk mailing list -> Delphi-Talk@elists.org http://lists.elists.org/cgi-bin/mailman/listinfo/delphi-talk