Login ProductsSalesSupportDownloadsAbout |
Home » Technical Support » ElevateDB Technical Support » Support Forums » ElevateDB General » View Thread |
Messages 1 to 8 of 8 total |
Blob field loading with a stream |
Tue, Oct 14 2014 6:46 AM | Permanent Link |
Peter Evans | (I am using Delphi XE6 with ElevateDB unicode version.)
I pass in an object TMemObj which has various Properties. One of them is Picture. This is a TStream. On the database it is a Blob field. Procedure TServerMethods1.TableMemParams( const AObj : TMemObj; var AQuery : TEDBQuery); begin WITH AQuery DO BEGIN { a number of Parameters then } if Assigned(AObj.Picture) then begin AObj.Picture.Position := 0; ParamByName('Param_Picture').AsStream := TMemoryStream.Create; ParamByName('Param_Picture').LoadFromStream(AObj.Picture, ftBlob); {crashes here} end else ParamByName('Param_Picture').AsString := ''; END; end; Out of curiosity I tried ParamByName('Param_Picture').AsString := 'ABCDEF'; This line did place that string into the database! So how do I the TStream from the Picture in the object into the Param? I realise that this has been asked before but whatever I try I can't get anything to work. Regards, Peter Evans |
Tue, Oct 14 2014 7:05 AM | Permanent Link |
Matthew Jones | Peter Evans wrote:
> ParamByName('Param_Picture').AsStream := TMemoryStream.Create; That's the problem I'd say. The field is responsible for it's own management. I don't understand this line. The rest should work, assuming of course that the parameter does exist - otherwise it would return nil and you then call a function of it. -- Matthew Jones |
Tue, Oct 14 2014 8:32 AM | Permanent Link |
Roy Lambert NLH Associates Team Elevate | Peter
I'm with Matthew. I don't know what > ParamByName('Param_Picture').AsStream := TMemoryStream.Create; is meant to do, or what it does to the table. This is what I do - its a bit different because I'm loading a Word document in but the essence is the same. FileIn := TMemoryStream.Create; FileIn.LoadFromFile(LinkedDocsFrame1.Docs_File.AsString); FileIn.Position := 0; Contacts_LatestCV.LoadFromStream(FileIn); Contacts_LatestCVDate.AsDateTime := LinkedDocsFrame1.Docs_DateLinked.AsDateTime; FileIn.Free; You could also treat your picture as a binary string and just use .AsString := 'X'+binary string I think Roy Lambert |
Tue, Oct 14 2014 8:44 AM | Permanent Link |
Matthew Jones | Roy Lambert wrote:
> You could also treat your picture as a binary string and just use > .AsString := 'X'+binary string If Rudy were here you'd be shot! 8-) But yes, I too have had binary data in a string (AnsiString for byte-safety) and assigned it, but streams are a lot more reliable. -- Matthew Jones |
Tue, Oct 14 2014 9:17 AM | Permanent Link |
Roy Lambert NLH Associates Team Elevate | Matthew
>If Rudy were here you'd be shot! 8-) I've already had one long discussion with Rudy on pointers. If he wants another one on improper use of strings I'm ready for it! I do agree with your comments about use AnsiString though, or if you want to be a purist use an array of bytes (which to me translates into an ansistring Roy |
Tue, Oct 14 2014 11:14 AM | Permanent Link |
Adam Brett Orixa Systems | Peter,
I tend to use a TJPEGImage component, I think this is a standard Delphi component. It has an "Assign" method which seems to be capable of accepting most of the photo-file formats I throw at it. The following usually works: aJPG:= TJpegImage.create; aJPG.Assign(AObj.Picture); Query.ParamByName('Picture').Assign(aJPG); Query.ExecSQL; aJPG.Free; It might even work without the intermediate step! i.e. Query.ParamByName('Picture').Assign(AObj.Picture); If the images are not JPG format I am not sure what happens exactly. I think it usually copes. I know I have code which also uses a TBitmap in a similar way, which I can dig out if it is helpful. |
Thu, Oct 16 2014 7:56 PM | Permanent Link |
Peter Evans | Thanks to everyone's replies. I am still working on a solution. Will
respond in full then. Regards, Peter Evans |
Sun, Oct 19 2014 8:10 PM | Permanent Link |
Peter Evans | > Thanks to everyone's replies. I am still working on a solution. Will Thank you for all the replies. It seems there was nothing wrong with ElevateDB and the way it stored the Blob field. There was nothing wrong with the LoadFromStream either. What was wrong was my understanding of how DataSnap moved data from the client to and from the DataSnap server. Things are working now. Regards, Peter Evans |
This web page was last updated on Tuesday, April 30, 2024 at 03:55 PM | Privacy PolicySite Map © 2024 Elevate Software, Inc. All Rights Reserved Questions or comments ? E-mail us at info@elevatesoft.com |