它們實現中調用的CheckValue是TReader的私有方法
procedure TReader
begin
if ReadValue <> Value then
begin
Dec(FBufPos)
SkipValue;
PropValueError;
end;
end;
CheckValue方法的功能是檢測緊接著要讀的值是否是Value指定的類型
EndOfList函數只是簡單地判斷下一字節是否是VaNull將判斷結果返回
簡單數據類型指的是布爾型
因為它們的實現都用到了ReadValue方法
function TReader
begin
Read(Result
end;
該方法調用私有方法Read
ReadValue方法專門從流中讀取值的類型的
function TReader
var
S: Shortint;
I: Smallint;
begin
case ReadValue of
vaInt
begin
Read(S
Result := S;
end;
vaInt
begin
Read(I
Result := I;
end;
vaInt
Read(Result
else
PropValueError;
end;
end;
因為Delphi
布爾類型的數據是直接放在值類型標志上
function TReader
begin
Result := ReadValue = vaTrue;
end;
ReadString方法也利用ReadValue方法判斷是字符串還是長字符串
function TReader
var
L: Integer;
begin
L :=
case ReadValue of
vaString:
Read(L
vaLString:
Read(L
else
PropValueError;
end;
SetString(Result
Read(Pointer(Result)^
end;
如果VaString類型緊接著一個字節存有字符串的長度
ReadFloat方法允許將整型值轉換為浮點型
function TReader
begin
if ReadValue = vaExtended then Read(Result
begin
Dec(FBufPos)
Result := ReadInteger;
end;
end;
字符類型數據設有直接的標志
function TReader
begin
CheckValue(vaString)
Read(Result
if Ord(Result) <>
begin
Dec(FBufPos)
ReadStr;
PropValueError;
end;
Read(Result
end;
出於讀取DFM文件需要
function TReader
var
L: Byte;
begin
case ReadValue of
vaIdent:
begin
Read(L
SetString(Result
Read(Result[
end;
vaFalse:
Result :=
vaTrue:
Result :=
vaNil:
Result :=
else
PropValueError;
end;
end;
一般說來
Reader對象中用於讀取部件的方法有ReadSignature
ReadSignature方法主要用於讀取Delphi Filer對象標簽一般在讀取部件前
procedure TReader
var
Signature: Longint;
begin
Read(Signature
if Signature <> Longint(FilerSignature) then ReadError(SInvalidImage)
end;
FilerSignature就是Filer對象標簽其值為
ReadPrefix方法是用於讀取流中部件前的標志位
procedure TReader
var
Prefix: Byte;
begin
Flags := [];
if Byte(NextValue) and $F
begin
Prefix := Byte(ReadValue)
Byte(Flags) := Prefix and $
if ffChildPos in Flags then AChildPos := ReadInteger;
end;
end;
TFilerFlags的定義是這樣的
TFilerFlag = (ffInherited
TFilerFlags = Set of TFilerFlag;
充當標志的字節的高四位是$F
ReadComponent方法用於從Reader對象的流中讀取部件
function TReader
var
CompClass
Flags: TFilerFlags;
Position: Integer;
…
begin
ReadPrefix(Flags
CompClass := ReadStr;
CompName := ReadStr;
Result := Component;
if Result = nil then
if ffInherited in Flags then
FindExistingComponent else
CreateComponent;
if Result <> nil then
try
Include(Result
if not (ffInherited in Flags) then SetCompName;
if Result = nil then Exit;
Include(Result
Result
Exclude(Result
if ffChildPos in Flags then Parent
FLoaded
except
if ComponentCreated then Result
raise;
end;
end;
ReadCompontent方法首先調用ReadPrefix方法
● 如果ffInberited 置位則從Root 找已有部件
● 如果結果不為空
[
From:http://tw.wingwit.com/Article/program/Delphi/201311/25094.html