2. Implementation of DefineProperty and Definebinaryproperty methods
These two methods are virtual methods, which are abstract methods in Tfiler and have specific implementations in Treader and Twriter objects.
They are implemented in Treader as follows:
Procedure Treader.defineproperty (const name:string; Readdata:treaderproc;
Writedata:twriterproc; Hasdata:boolean);
Begin
If Comparetext (Name, fpropname) = 0 Then
Begin
ReadData (Self);
Fpropname: = ';
End
End
Procedure Treader.definebinaryproperty (const name:string;
ReadData, Writedata:tstreamproc; Hasdata:boolean);
Var
Stream:tmemorystream;
Count:longint;
Begin
If Comparetext (Name, fpropname) = 0 Then
Begin
If ReadValue <> Vabinary Then
Begin
Dec (Fbufpos);
Skipvalue;
Fcanhandleexcepts: = True;
Propvalueerror;
End
Stream: = tmemorystream.create;
Try
Read (Count, SizeOf (count));
Stream.setsize (Count);
Read (stream.memory^, Count);
Fcanhandleexcepts: = True;
ReadData (Stream);
Finally
Stream.free;
End
Fpropname: = ';
End
End
In all two methods, the name parameter value is compared to the current property name, and if the same is read. In Definebinaryproperty, a memory stream was created. Read the data into the memory stream and then call ReadData to read the data.
3. Implementation of Flushbuffer
The Flushbuffer method is used to clear the contents of the reader object's internal buffer, keeping the reader object synchronized with the stream at position (Position), which is implemented as follows:
Procedure Treader.flushbuffer;
Begin
Fstream.position: = fstream.position-(fbufend-fbufpos);
Fbufpos: = 0;
Fbufend: = 0;
End
4. Readlistbegin, Readlistend and Endoflist methods
These three methods are used to read a series of items from the stream of the reader object, and these items are writelistbegin written by the mark of the start and Writelistend write flags, calibration end, in the reading loop with Endoflist to judge. They are often used when the reader object reads the data in the stream. They are implemented as follows:
Procedure Treader.readlistbegin;
Begin
CheckValue (valist);
End
Procedure Treader.readlistend;
Begin
CheckValue (Vanull);
End
function TReader.EndOfList:Boolean;
Begin
Result: = ReadValue = Vanull;
Dec (Fbufpos);
End
The project table start flag is valist, and the project table end flag is vanull,valist and vanull are constants defined by enumerated type Tvaluetype.
The CheckValue called in their implementation is the Treader private method, which is implemented as follows:
Procedure Treader.checkvalue (Value:tvaluetype);
Begin
If ReadValue <> Value Then
Begin
Dec (Fbufpos);
Skipvalue;
Propvalueerror;
End
End
The function of the CheckValue method is to detect whether the value that is to be read immediately is the type specified by value. If not, skip the item and trigger a sinvalidpropertyvalue error.
The Endoflist function simply determines whether the next byte is vanull returns the result of the judgment and moves the byte back to its original position.