开发Delphi对象式数据管理功能(八)(6)

2008-02-23 07:16:49来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折

if GlobalLoaded <> nil then

FLoaded := GlobalLoaded else

FLoaded := TList.Create;

try

FLoaded.Add(FRoot);

FOwner := FRoot;

Include(FRoot.FComponentState, csLoading);

Include(FRoot.FComponentState, csReading);

FRoot.ReadState(Self);

Exclude(FRoot.FComponentState, csReading);

if GlobalLoaded = nil then

for I := 0 to FLoaded.Count - 1 do TComponent(FLoaded[I]).Loaded;

finally

if GlobalLoaded = nil then FLoaded.Free;

FLoaded := nil;

end;

GlobalFixupReferences;

except

RemoveFixupReferences(Root, '');

if Root = nil then Result.Free;

raise;

end;

end;

 

  ReadRootComponent首先调用ReadSignature读取Filer对象标签。然后在tryexcept循环中执行读取任务。如果Root参数为nil,则用ReadStr读出的类名创建新部件,并以流中读出部件的Name属性;否则,忽略类名,并判断Name属性的唯一性。最后用RootReadState方法读取属性和其拥有的拥有并处理引用关系。

  7. SetName方法和OnSetName事件

  因为在OnSetName事件中,Name参数是var型的,所以可以用OnSetName事件处理过程修改所读部件的名字。而OnSetName事件处理过程是在SetName方法中实现的。

 

procedure TReader.SetName(Component: TComponent; var Name: string);

begin

if Assigned(FOnSetName) then FOnSetName(Self, Component, Name);

Component.Name := Name;

end;

 

SetName方法和OnSetName事件在动态DFM文件的编程中有很重要的作用。

  8. TReader的错误处理

  TReader的错误处理是由Error方法和OnError事件的配合使用完成的。OnError 事件处理过程的Handled参数是var型的布尔变量,通过将Handled设为TrueFalse可影响TReader 的错误处理。OnError事件处理过程是在Error方法中调用的。

 

function TReader.Error(const Message: string): Boolean;

begin

Result := False;

if Assigned(FOnError) then FOnError(Self, Message, Result);

end;

 

  9. FindMethodOnFindMethod事件

  有时,在程序运行期间,给部件的方法指针(主要是事件处理过程)动态赋值是很有用的,这样就能动态地改变部件响应事件的方式。在流中读取部件捍做到一点就要利用OnFindMehtod事件。OnFIndMethod事件是在

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:Delphi 剪贴板和动态数据交换(二)

下一篇:Delphi 剪贴板和动态数据交换(三)