Writes data from a memory buffer to a BLOB field object.
function Write(const Buffer; Count: Longint): Longint; override;
virtual __fastcall Longint Write(const Buffer, Longint Count);
Use Write to copy data from a null-terminated string (or comparable) buffer in memory to the BLOB field object. Write copies data from the buffer to the current position in the BLOB field object (current position indicated by the Position property). Write copies the number of bytes specified in Count or the number of bytes remaining in the memory buffer (counting from the current position to the end), whichever is less. Write can be called multiple times during the lifetime of a TADOBlobStream, each call copying less than the total number of bytes to be copied.
Count represents the maximum number of bytes to copy in a single call to Write. Count may be less than, the same as, or greater than the number of bytes actually contained in the memory buffer. If Count is greater than the actual number of bytes present or remaining in the memory buffer, copying stops at the last byte. No penalty is incurred on exceptions generated by specifying a number greater than the actual size of the contents.
Write updates the Size property to Position + Count, and sets the Position property to the new value of Size. Thus, any data that was stored in the memory stream in the Count bytes after the current position is lost when calling Write.
After successful execution, Write returns the number of bytes copied to the BLOB field object. If the return value is less than Count, the most likely reason is that the end of the buffer was reached prior to copying the specified number of bytes.
var P: PChar; S: Integer; BS:TADOBlobStream; begin if not (ADOTable1.State in [dsEdit, dsInsert]) then ADOTable1.Edit; BS := TADOBlobStream.Create(TMemoField(ADOTable1.Fields), bmWrite); try S := Memo1.GetTextLen; Inc(S); P := AllocMem(S); FillChar(P^, S, #0); Memo1.GetTextBuf(P, S); BS.Write(P^, S); finally BS.Free; FreeMem(P, S); end; end;
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!