看了VCL的Form部分,很多不明白的。请教constructor TCustomForm.Create(AOwner: TComponent);
begin
  GlobalNameSpace.BeginWrite;
  try
    CreateNew(AOwner);
    if (ClassType <> TForm) and not (csDesigning in ComponentState) then
    begin
      Include(FFormState, fsCreating);
      try
        if not InitInheritedComponent(Self, TForm) then
          raise EResNotFound.CreateFmt(SResNotFound, [ClassName]);
      finally
        Exclude(FFormState, fsCreating);
      end;
      if OldCreateOrder then DoCreate;
    end;
  finally
    GlobalNameSpace.EndWrite;
  end;
end;一看就知道是作用是创建还有必要的初始化。不过,问题来了:
GlobalNameSpace干什么的?
GlobalNameSpace.BeginWrite 的作用?IReadWriteSync里怎么没有实现?
Include(FFormState, fsCreating) 的作用?
Exclude(FFormState, fsCreating) 的作用?
GlobalNameSpace.EndWrite 的作用?IReadWriteSync里怎么没有实现?

解决方案 »

  1.   

    IReadWriteSync里怎么没有实现?  
        IReadWriteSync是一个接口定义, 在WINDOWS中他是通过TMultiReadExclusiveWriteSynchronizer这个类来实现的,在CLX中是通过TSimpleRWSync这个类来实现的。
        下面的代码来自CLASSES中初始化部分。
        {$IFDEF MSWINDOWS}
          GlobalNameSpace := TMultiReadExclusiveWriteSynchronizer.Create;
       {$ENDIF}
       {$IFDEF LINUX}
          GlobalNameSpace := TSimpleRWSync.Create;
       {$ENDIF}
    Include(FFormState, fsCreating) 的作用?   
         FFormState是一个SET, 这句就是让FFormState里包含fsCreating这个值
    Exclude(FFormState, fsCreating) 的作用?   
         去掉fsCreating这个值
    GlobalNameSpace干什么的?这个作用请看:
       Use TMultiReadExclusiveWriteSynchronizer to guard access to memory in a multi-threaded application. Unlike a critical section, which blocks all other threads from reading or writing its associated memory, TMultiReadExclusiveWriteSynchronizer allows multiple threads to read from the protected memory simultaneously, while ensuring that any thread writing to the memory has exclusive access.In applications where threads read from an object or variable frequently and only write to it occasionally, using the multi-read exclusive-write synchronizer instead of a critical section can result in considerable performance improvement.All access to the protected memory must be bracketed by calls to the BeginRead and EndRead or BeginWrite and EndWrite methods. Any thread that reads from or writes to this memory without using these calls can introduce thread conflicts.
      

  2.   

    to netfly(支点) 
    谢谢至于你最后说的,都是E文。偶的E文不好。所以你白Paste了
    给点中文的好么?
      

  3.   

    类似一个互斥对象,确保在CREATE和DESTORY的时候,只有本FORM进行。
      

  4.   

    Include和Exclude也有实现么?
    VCL面太大了。看不过来
      

  5.   

    是函数。DELPHI在代码编辑窗口中将光标定位在某个词上按F1可以弹出这个词的帮助。
      

  6.   

    厉害。看来这50分都得给你(netfly(支点) )了