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

  WriteString方法用于写入字符串

  

procedure TWriter.WriteString(const Value: string);

var

L: Integer;

begin

L := Length(Value);

if L <= 255 then

begin

WriteValue(vaString);

Write(L, SizeOf(Byte));

end else

begin

WriteValue(vaLString);

Write(L, SizeOf(Integer));

end;

Write(Pointer(Value)^, L);

end;

 

  Delphi的字符串类型有两种。一种长度小于256个字节,另一种长度小于65536 个字节。WriteString方法区分这两类情况存储字符串,一种设置VaStirng标志,另一种设置VaLString。然后存储字符串的长度值,最后存储字符串数据。

  WriteChar方法用于写入字符。

  

procedure TWriter.WriteChar(Value: Char);

begin

WriteString(Value);

end;

 

  字符类型的读写是用读写字符串的方法,在读的时候,判断字节数为1时,则为字符型。

  ⑶ 部件的写入

  TWriter对象中与写入部件有关的方法有WriteSignature、WritePrefix、WriteComponent、WriteDescendant和WriteRootComponent。

 WriteSignature方法用于往流中写入Filer对象标签。

 

procedure TWriter.WriteSignature;

begin

Write(FilerSignature, SizeOf(FilerSignature));

end;

 

  FilerStgnature是字符串常量,其值为“TPF0”,代表对象标签。

  WritePrefix方法用于在写入部件前写入ffInherited和ffChildPos标志,这些标志表示部件的继承特征和创建序值特征。

 

procedure TWriter.WritePrefix(Flags: TFilerFlags; AChildPos: Integer);

var

Prefix: Byte;

begin

if Flags <> [] then

begin

Prefix := $F0 or Byte(Flags);

Write(Prefix, SizeOf(Prefix));

if ffChildPos in Flags then WriteInteger(AChildPos);

end;

end;

 

  如果ffChildPos置位,则存入部件在Owner中的创建序值。更详细的信息请参阅TReader的ReadPrefix方法。

  WriteComponent方法往流中写入部件。

 

procedure TWriter.WriteComponent(Component: TComponent);

 

function FindAncestor(const Name: string): TComponent;

begin

end;

 

begin

Include(Component.FComponentState, csWriting);

if Assigned(FAncestorList) then

Ancestor := FindAncestor(Component.Name);

Component.WriteState(Self);

Exclude(Component.FComponentState, csWriting);

end;

 

  方法中用Component的WritState方法写入部件的属性。在写入之前将Component.FComponentState置为csWriting写入完后再将csWriting复位。

  WriteDescendant是根据祖先AAncestor的情况写入部件Root。

 

procedure TWriter.WriteDescendent(Root: TComponent; AAncestor: TComponent);

begin

FRootAncestor := AAncestor;

FAncestor := AAncestor;

FRoot := Root;

WriteSignature;

WriteComponent(Root);

end;

 

方法先调用WriteSignature方法写入Filer对象标签。然后调用WriteComponent将部件Root写入流。

  WriteRootComponent方法则是调用WriteDescendant方法写入部件,只是将后者的Ancestor参数以nil值传入。 

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

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

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

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

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

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

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

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

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

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

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

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

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