Data.Win.ADODB.TADOBlobStream.Write

From RAD Studio API Documentation
Jump to: navigation, search

Delphi

function Write(const Buffer; Count: Longint): Longint; override;

C++

virtual int __fastcall Write(const void *Buffer, int Count)/* overload */;
inline int __fastcall  Write(const System::DynamicArray<System::Byte> Buffer, int Offset, int Count){ return System::Classes::TStream::Write(Buffer, Offset, Count); }
inline int __fastcall  Write(const System::DynamicArray<System::Byte> Buffer, int Count){ return System::Classes::TStream::Write(Buffer, Count); }

Properties

Type Visibility Source Unit Parent
function public
Data.Win.ADODB.pas
Data.Win.ADODB.hpp
Data.Win.ADODB TADOBlobStream

Description

Writes data from a memory buffer to a BLOB field object.

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[1]), 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;



int S;
ADOTable1->Edit();
TADOBlobStream *BS = new TADOBlobStream(ADOTable1->Fields->Fields[1], bmWrite);
try
{
S = Memo1->GetTextLen() + 1;
char *P = new char[S];
Memo1->GetTextBuf(P, S);
BS->Write(P.c_str(), P.Length());
}
__finally
{
delete BS;
}



See Also