| 网站首页 | JAVA文章 | AppServers | Web开发 | 应用开发 | 资源下载 | 论坛
    想学好编程,学好外语很重要  [enadd  2006年12月25日]        
设为首页 加入收藏 联系站长
您现在的位置: 编程笔记网 >> 应用开发 >> delphi >> 基础教程 >> 文章正文
第二十章 开发Delphi对象式数据管理功能(四)            【字体:
第二十章 开发Delphi对象式数据管理功能(四)
作者:不祥    文章来源:-    点击数:    更新时间:2006-12-12

begin

Read(Signature, SizeOf(Signature));

if Signature <> Longint(FilerSignature) then ReadError(SInvalidImage);

end;

 

FilerSignature就是Filer对象标签其值为“TPF0” ,如果读的不是“TPF0” ,则会触发SInValidImage异常事件。

  ReadPrefix方法是用于读取流中部件前的标志位,该标志表示该部件是否处于从祖先窗体中继承的窗体中和它在窗体中的位置是否很重要。

 

procedure TReader.ReadPrefix(var Flags: TFilerFlags; var AChildPos: Integer);

var

Prefix: Byte;

begin

Flags := [];

if Byte(NextValue) and $F0 = $F0 then

begin

Prefix := Byte(ReadValue);

Byte(Flags) := Prefix and $0F;

if ffChildPos in Flags then AChildPos := ReadInteger;

end;

end;

 

  TFilerFlags的定义是这样的:

 

   TFilerFlag = (ffInherited, ffChildPos);

TFilerFlags = Set of TFilerFlag;

 

充当标志的字节的高四位是$F,低四位是集合的值,也是标志位的真正含义。如果ffChildPos置位,则紧接着的整型数字中放着部件在窗体中的位置序值。

  ReadComponent方法用于从Reader对象的流中读取部件。Component 参数指定了要从流中读取的对象。函数返回所读的部件。

 

function TReader.ReadComponent(Component: TComponent): TComponent;

var

CompClass, CompName: string;

Flags: TFilerFlags;

Position: Integer;

 

begin

ReadPrefix(Flags, Position);

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.FComponentState, csLoading);

if not (ffInherited in Flags) then SetCompName;

if Result = nil then Exit;

Include(Result.FComponentState, csReading);

Result.ReadState(Self);

Exclude(Result.FComponentState, csReading);

if ffChildPos in Flags then Parent.SetChildOrder(Result, Position);

FLoaded.Add(Result);

except

if ComponentCreated then Result.Free;

raise;

end;

end;

 

ReadCompontent方法首先调用ReadPrefix方法,读出部件标志位和它的创建次序值(Create Order)。然后用ReadStr方法分别读出部件类名和部件名。如果Component参数为nil,则执行两个任务:

● 如果ffInberited 置位则从Root 找已有部件,否则,就从系统的Class表中找到该部件类型的定义并创建

● 如果结果不为空,将用部件的ReadState方法读入各种属性值,并设置部件的Parent 属性,并恢复它在Parent部件的创建次序。

 

  ReadComponent方法主要是调用ReadComponent方法从Reader对象的流中读取一连串相关联的部件,并分解相互引用关系。

 

procedure TReader.ReadComponents(AOwner, AParent: TComponent;

Proc: TReadComponentsProc);

var

Component: TComponent;

begin

Root := AOwner;

Owner := AOwner;

Parent := AParent;

BeginReferences;

try

while not EndOfList do

begin

ReadSignature;

上一页  [1] [2] [3] [4] [5] [6] [7] [8] 下一页  

文章录入:enadd    责任编辑:enadd 
  • 上一篇文章:

  • 下一篇文章:
  • 发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
    最新热点 最新推荐 相关文章
  • 第二十章 开发Delphi对象式…

  • 第二十章 开发Delphi对象式…

  • 第二十章 开发Delphi对象式…

  • 第二十章 开发Delphi对象式…

  • 第十九章 Delphi自定义部件…

  • 第十九章 Delphi自定义部件…

  • 第十九章 Delphi自定义部件…

  • 第十九章 Delphi自定义部件…

  • 第十八章 Delphi客户服务器…

  • 第十八章 Delphi客户服务器…

  •   网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)
    | 设为首页 | 加入收藏 | 联系站长 | 友情链接 | 版权申明 | 管理登录 |