首页 > Windows开发 > 详细

TComponent,TControl,TWinControl,TCustomForm,TGraphic,TPicture的DefineProperties赏析与说明(不是很懂)

时间:2016-03-13 21:10:22      阅读:568      评论:0      收藏:0      [点我收藏+]

先观赏一下最后的实现效果:

object Form1: TForm1
  Left = 192
  Top = 107
  Width = 870
  Height = 500
  Caption = Form1
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = MS Shell Dlg 2
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object Image1: TImage
    Left = 112
    Top = 160
    Width = 105
    Height = 105
    Picture.Data = {
      0A544A504547496D616765784A0000FFD8FFE000104A46494600010100000100
      010000FFFE003B43524541544F523A2067642D6A7065672076312E3020287573
      696E6720494A47204A50454720763632292C207175616C697479203D2035350A
      A4C50021A4A7639A42281098A4A5A31400948694D18A004C5252D1400D228A53
      498A004A314B46280003270064D4806D18CFD7DE855C004F04F4CD3801D6AD2B
      4E3A679AF123C527B51617297B5B9125D775192370E8F73232B29C86058E0834
      550A29947FFFD9}
  end
  object Panel1: TPanel
    Left = 480
    Top = 40
    Width = 185
    Height = 41
    Caption = Panel1
    TabOrder = 0
  end
  object Button1: TButton
    Left = 288
    Top = 32
    Width = 75
    Height = 25
    Caption = Button1
    TabOrder = 1
  end
  object Button2: TButton
    Left = 376
    Top = 168
    Width = 75
    Height = 25
    Caption = Button2
    TabOrder = 2
    OnClick = Button2Click
  end
end

VCL的实现代码:

procedure TComponent.DefineProperties(Filer: TFiler);
var
  Ancestor: TComponent;
  Info: Longint;
begin
  Info := 0;
  Ancestor := TComponent(Filer.Ancestor);
  if Ancestor <> nil then Info := Ancestor.FDesignInfo;
  Filer.DefineProperty(Left, ReadLeft, WriteLeft,
    LongRec(FDesignInfo).Lo <> LongRec(Info).Lo);
  Filer.DefineProperty(Top, ReadTop, WriteTop,
    LongRec(FDesignInfo).Hi <> LongRec(Info).Hi);
end;

存储Left与Top的值。另外Height和Width是在哪里存储的?

procedure TControl.DefineProperties(Filer: TFiler);

  function DoWriteIsControl: Boolean;
  begin
    if Filer.Ancestor <> nil then
      Result := TControl(Filer.Ancestor).IsControl <> IsControl else
      Result := IsControl;
  end;
begin
  { The call to inherited DefinedProperties is omitted since the Left and
    Top special properties are redefined with real properties }
  Filer.DefineProperty(‘IsControl‘, ReadIsControl, WriteIsControl, DoWriteIsControl);
end;

存储IsControl的值,但是我怎么没见到?

procedure TWinControl.DefineProperties(Filer: TFiler);

  function PointsEqual(const P1, P2: TPoint): Boolean;
  begin
    Result := ((P1.X = P2.X) and (P1.Y = P2.Y));
  end;

  function DoWriteDesignSize: Boolean;
  var
    I: Integer;
  begin
    Result := True;
    if (Filer.Ancestor = nil) or not PointsEqual(FDesignSize,
      TWinControl(Filer.Ancestor).FDesignSize) then
    begin
      if FControls <> nil then
        for I := 0 to FControls.Count - 1 do
          with TControl(FControls[I]) do
            if (Align = alNone) and (Anchors <> [akLeft, akTop]) then
              Exit;
      if FWinControls <> nil then
        for I := 0 to FWinControls.Count - 1 do
          with TControl(FWinControls[I]) do
            if (Align = alNone) and (Anchors <> [akLeft, akTop]) then
              Exit;
    end;
    Result := False;
  end;

begin
  inherited;
  Filer.DefineProperty(‘DesignSize‘, ReadDesignSize, WriteDesignSize,
    DoWriteDesignSize);
end;

存储DesignSize的值

procedure TCustomForm.DefineProperties(Filer: TFiler);
begin
  inherited DefineProperties(Filer);
  Filer.DefineProperty(‘PixelsPerInch‘, nil, WritePixelsPerInch, not IsControl);
  Filer.DefineProperty(‘TextHeight‘, ReadTextHeight, WriteTextHeight, not IsControl);
  Filer.DefineProperty(‘IgnoreFontProperty‘, ReadIgnoreFontProperty, nil, False);
end;

写入三个值,但是我怎么没见到?

procedure TGraphic.DefineProperties(Filer: TFiler);

  function DoWrite: Boolean;
  begin
    if Filer.Ancestor <> nil then
      Result := not (Filer.Ancestor is TGraphic) or
        not Equals(TGraphic(Filer.Ancestor))
    else
      Result := not Empty;
  end;

begin
  Filer.DefineBinaryProperty(‘Data‘, ReadData, WriteData, DoWrite);
end;

写入Data的二进制数据

// TPicture直接继承于TInterfacedPersistent,与TGraphic相互独立
procedure TPicture.DefineProperties(Filer: TFiler); 

  function DoWrite: Boolean;
  var
    Ancestor: TPicture;
  begin
    if Filer.Ancestor <> nil then
    begin
      Result := True;
      if Filer.Ancestor is TPicture then
      begin
        Ancestor := TPicture(Filer.Ancestor);
        Result := not ((Graphic = Ancestor.Graphic) or
          ((Graphic <> nil) and (Ancestor.Graphic <> nil) and
          Graphic.Equals(Ancestor.Graphic)));
      end;
    end
    else Result := Graphic <> nil;
  end;

begin
  Filer.DefineBinaryProperty(‘Data‘, ReadData, WriteData, DoWrite);
end;

写入Data的二进制数据

TComponent,TControl,TWinControl,TCustomForm,TGraphic,TPicture的DefineProperties赏析与说明(不是很懂)

原文:http://www.cnblogs.com/findumars/p/5273127.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!