组件开发/不同设计师与运行时

时间:2014-12-22 10:36:29

标签: delphi delphi-xe

我想创建自己的作品  1. FAMPanel => TPanel->行。

unit famui;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ExtCtrls;

type

  CorporateDesign = record
    white: TColor;
    black: TColor;
    gray: TColor;
    darkgray: TColor;
    blue: TColor;
    blueLight: TColor;
    red: TColor;
    font: String;
  end;

  FAMPanel = class(TPanel)
  private
    { Private-Deklarationen }
  protected
    { Protected-Deklarationen }
  public
    { Public-Deklarationen }
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  published
    { Published-Deklarationen }
  end;

const
  _CorporateDesign: CorporateDesign = (white: clWhite; black: clBlack;
    gray: $00F8F8F8; darkgray: $00E5E5E5; blue: $00D37C00; blueLight: $00E9BE80;
    red: $001619DA; font: 'Roboto Light');

implementation

{ FAMPanel }

constructor FAMPanel.Create(AOwner: TComponent);
begin
  inherited;
  self.BevelInner := bvNone;
  self.BevelOuter := bvNone;
  self.Color := _CorporateDesign.white;
  self.font.Name := _CorporateDesign.font;
end;

destructor FAMPanel.Destroy;
begin

  inherited;
end;

end. 

2。 FAMCard => FAMPanel - > OK。
 2.1将3个面板(FAMPanel)添加到(FAMCard) - >行

unit card;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ExtCtrls, famui;

type

  FAMCard = class(FAMPanel)
  private
    { Private-Deklarationen }
    Header: FAMPanel;
    Content: FAMPanel;
    Footer: FAMPanel;
  protected
    { Protected-Deklarationen }
  public
    { Public-Deklarationen }
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  published
    { Published-Deklarationen }
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('FAMUI', [FAMCard]);
end;

{ TFamGUI }

constructor FAMCard.Create(AOwner: TComponent);
begin
  inherited;

  // Default size of fam card
  self.Width := 600;
  self.Height := 400;

  // Create header of card
  Header := FAMPanel.Create(self);
  Header.Parent := self;
  Header.Color := _CorporateDesign.gray;
  Header.Align := alTop;
  Header.Height := 90;

  // Create content of card
  Content := FAMPanel.Create(self);
  Content.Parent := self;
  Content.Color := _CorporateDesign.white;
  Content.Align := alClient;

  // Create footer of card
  Footer := FAMPanel.Create(self);
  Footer.Parent := self;
  Footer.Color := _CorporateDesign.gray;
  Footer.Align := alBottom;
  Footer.Height := 90;

end;

destructor FAMCard.Destroy;
begin
  inherited;

end;

end. 
  1. 设计师中的新项目/组件 - >好
  2. 编译后 - >错误,页眉内容和页脚区域被隐藏(显示:无) enter image description here
  3. 为什么?

1 个答案:

答案 0 :(得分:0)

FAMPanel源自TPanel。 TPanel.ParentBackground的默认值为True,这会阻止您的代码在主题环境中设置Color属性。

修复很简单,只需在FAMPanel.Constructor中添加标记的行:

constructor FAMPanel.Create(AOwner: TComponent);
begin
  inherited;
  self.BevelInner := bvNone;
  self.BevelOuter := bvNone;
  self.ParentBackground := False;  // Add this line
  self.Color := _CorporateDesign.white;
  self.font.Name := _CorporateDesign.font;
end;