Ole Ekerhovd 0 Posted April 26, 2019 This code gives an error, "Invalid Pointer Operation". It's the aBlob.Free that triggers the error. What's wrong in my code? I should Free I guess? var aBlob : TBlobField; aStream : TStream; try ablob:=aQuery.fieldbyname('Memo') as tblobfield; astream:=Tmemorystream.Create; astream := aquery.CreateBlobStream(ablob, bmRead); amemo.Lines.LoadFromStream(astream); finally ablob.Free; astream.Free; end; Share this post Link to post
Remy Lebeau 1393 Posted April 26, 2019 (edited) Why are you freeing the TBlobField at all? You don't own it, the Query component does, so you should not be freeing it at all. Also, you are leaking the TMemoryStream that you create (which you should not be creating in the first place). The only thing you should be freeing manually is the TStream that CreateBlobStream() returns, eg: var aBlob : TField; aStream : TStream; begin aBlob := aQuery.FieldByName('Memo'); aStream := aQuery.CreateBlobStream(aBlob, bmRead); try aMemo.Lines.LoadFromStream(aStream); finally aStream.Free; end; end; Edited April 26, 2019 by Remy Lebeau 1 Share this post Link to post
Ole Ekerhovd 0 Posted April 26, 2019 Thanks Remy, really appreciate it. Regards, Ole Share this post Link to post
David Heffernan 2345 Posted April 26, 2019 It's important to learn how to try finally is used. Like this resource := acquireResource; try resource.doSomething; finally resource.release; end; I've not use standard names here, but gone for a more conceptual presentation. The key is the order of things. Share this post Link to post