国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

通過原代碼學習TComponent類的機制(1)

2019-11-18 18:35:18
字體:
來源:轉載
供稿:網友
 學習DELPHI最好的方法是看DELPHI的VCL原代碼愛看他的機制本文就類TComponent的原代碼來看他的機制.
{ TComponent }
constructor TComponent.Create(AOwner: TComponent);
begin
  FComponentStyle := [csInheritable];
  if AOwner <> nil then AOwner.InsertComponent(Self);
end;

PRocedure TComponent.InsertComponent(AComponent: TComponent);
begin
  AComponent.ValidateContainer(Self);
  ValidateRename(AComponent, '', AComponent.FName);//看是否有重名的對象如果有則發異常
  Insert(AComponent);//在自己的子組件列表里加入AComponent的引用
  AComponent.SetReference(True);
  if csDesigning in ComponentState then
    AComponent.SetDesigning(True);
  Notification(AComponent, opInsert);//給自己發一個通知消息
end;

procedure TComponent.ValidateRename(AComponent: TComponent;
  const CurName, NewName: string);
begin
  if (AComponent <> nil) and not SameText(CurName, NewName) and
    (AComponent.Owner = Self) and (FindComponent(NewName) <> nil) then
    raise EComponentError.CreateResFmt(@SDuplicateName, [NewName]);
  if (csDesigning in ComponentState) and (Owner <> nil) then
    Owner.ValidateRename(AComponent, CurName, NewName);//遞歸調用查是否有重名的組件
end;

procedure TComponent.ValidateContainer(AComponent: TComponent);
begin
  AComponent.ValidateInsert(Self);
end;

procedure TComponent.ValidateInsert(AComponent: TComponent);
begin
end;

procedure TComponent.Insert(AComponent: TComponent);//我們可以看到他的子組件的引用是用TLIST來保存的
begin
  if FComponents = nil then FComponents := TList.Create;
  FComponents.Add(AComponent);
  AComponent.FOwner := Self;//給剛剛加上的主件賦上擁有者屬性
end;

destructor TComponent.Destroy; file://可以看到每一個組件都維護一個FFREENOTIFILES的列表
begin
  Destroying;
  if FFreeNotifies <> nil then
  begin
    while Assigned(FFreeNotifies) and (FFreeNotifies.Count > 0) do
      TComponent(FFreeNotifies[FFreeNotifies.Count - 1]).Notification(Self, opRemove);
    FreeAndNil(FFreeNotifies);//如果自己析構的時候,對自己FFREENOTIFILES里面引用的對象調用Notification,把自己析構造的事件告訴他們
  end;
  DestroyComponents;
  if FOwner <> nil then FOwner.RemoveComponent(Self);
  inherited Destroy;
end;

procedure TComponent.FreeNotification(AComponent: TComponent);//通過這個過程可以證實FFREENOTIFILES是一個列表這個列表維護自己析構的時候給那些對象通知
begin
  if (Owner = nil) or (AComponent.Owner <> Owner) then
  begin
    // Never acquire a reference to a component that is being deleted.
    assert(not (csDestroying in (ComponentState + AComponent.ComponentState)));
    if not Assigned(FFreeNotifies) then FFreeNotifies := TList.Create;
    if FFreeNotifies.IndexOf(AComponent) < 0 then
    begin
      FFreeNotifies.Add(AComponent);
      AComponent.FreeNotification(Self);
    end;
  end;
  Include(FComponentState, csFreeNotification);
end;


上一篇:DirectShow之接口實戰篇(三)

下一篇:使用XMLDocment遍歷CSDN論壇帖子回復

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
學習交流
熱門圖片

新聞熱點

疑難解答

圖片精選

網友關注

主站蜘蛛池模板: 绍兴县| 白河县| 蒙自县| 灌阳县| 江安县| 堆龙德庆县| 江油市| 隆安县| 芮城县| 明水县| 邵武市| 通山县| 同德县| 叶城县| 寿阳县| 通河县| 天等县| 南江县| 交城县| 化州市| 德化县| 望谟县| 新民市| 喜德县| 浑源县| 德州市| 平安县| 东宁县| 昌邑市| 茂名市| 玉环县| 吕梁市| 绥棱县| 敦化市| 清涧县| 麻江县| 乌鲁木齐市| 丹东市| 伊春市| 沭阳县| 荣成市|