2. Implementation of the Read and write methods
Both the read and write methods call the BDE API function to complete the reading and writing of the Database Blob field, which is implemented as follows:
function Tblobstream.read (var Buffer; Count:longint): Longint;
Var
Status:dbiresult;
Begin
Result: = 0;
If Fopened Then
Begin
Status: = Dbigetblob (Fdataset.handle, Frecord, Ffieldno, Fposition,
Count, @Buffer, result);
Case Status of
Dbierr_none, Dbierr_endofblob:
Begin
If Ffield.ftransliterate Then
Nativetoansibuf (Fdataset.locale, @Buffer, @Buffer, result);
Inc. (fposition, result);
End
Dbierr_invalidbloboffset:
{Nothing};
Else
Dbierror (Status);
End
End
End
The Read method reads data from the Fdataset using the Dbigetblob function of the BDE API, in this function, The meaning of each parameter is this: Fdataset.handle represents the BDE handle of the DataSet, Freacord represents the record of the Blob field, Ffieldno represents the Blob field number, the fposition represents the starting position of the data to read, and count represents the number of bytes to read, Buf Fer is the memory that reads the data, and result is the number of bytes actually read out. The BDE function returns error state information for a function call.
The Read method also invokes nativetoansibuf for the character set conversion.
function tblobstream.write (const Buffer; Count:longint): Longint;
Var
Temp:pointer;
Begin
Result: = 0;
If Fopened Then
Begin
If Ffield.ftransliterate Then
Begin
Getmem (Temp, Count);
Try
Ansitonativebuf (Fdataset.locale, @Buffer, Temp, Count);
Check (Dbiputblob (Fdataset.handle, Frecord, Ffieldno, Fposition,
Count, Temp));
Finally
Freemem (Temp, Count);
End
End Else
Check (Dbiputblob (Fdataset.handle, Frecord, Ffieldno, Fposition,
Count, @Buffer));
INC (Fposition, Count);
Result: = Count;
Fmodified: = True;
End
End
The Write method invokes the Dbiputblob function of the BDE API to store data in a database BLOB field.
The parameters of the function have the following meanings:
Table 20.2 Meaning of the incoming arguments that invoke the function Dbiputblob
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
The meaning of the parameter name
──────────────────────────────
BDE handle of the database written by Fdatasethandle
Frecord the record of the Blob field where the data is written
Ffieldno BLOB Field number
Start position of Fposition write
Number of bytes written by Count
The memory address that the data written by Buffer occupies
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
The method also determines whether the corresponding character set conversion is based on the value of Ffield and ftransliterate, moves the position pointer of the Blob stream, and then sets the modification flag fmodified to True.
3. Implementation of Seek and Getblobsize methods
The Seek method functions primarily as a position pointer for moving a BLOB stream. The Getblobsize method is private and is invoked in the Seek method, and its function is to get the size of the BLOB data. They are implemented as follows:
function TBlobStream.GetBlobSize:Longint;
Begin
Result: = 0;
If Fopened Then
Check (Dbigetblobsize (Fdataset.handle, Frecord, Ffieldno, result));
End
function Tblobstream.seek (offset:longint; Origin:word): Longint;
Begin
Case Origin of
0:fposition: = Offset;
1:inc (Fposition, Offset);
2:fposition: = Getblobsize + Offset;
End
Result: = Fposition;
End
Getblobsize called the dbigetblobsize function of the BDE API, which has the same meaning as the previous API function.