码迷,mamicode.com
首页 > 其他好文 > 详细

控件动态产生器(使用RegisterClasses提前进行注册)

时间:2016-10-12 06:59:03      阅读:107      评论:0      收藏:0      [点我收藏+]

标签:

代码

Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->unit pgDynamicGenerate;
//动态产生器

interface
uses
  pgGUISprite, pgGUIControls, DXSprite, Classes;


type
  TSpriteClass = class of TpgGUISprite;
  //定义一个类型数组

  TClassArray = array[1..6] of TSpriteClass;
const
  ClassArray: TClassArray = (TpgButton, TpgControl, TpgCustomEdit, TpgFontComponent, TpgForm, TpgMouse);

function pgSpriteCreate(SpriteClass: TSpriteClass; AParent: TSprite; const SpriteName: string = ‘‘): TpgGUISprite;
function GenerateComponent(const ClassName: string; AParent: TSprite; const SpriteName: string = ‘‘): TpgGUISprite;
procedure initRegisterClasses;
procedure finaUnRegisterClass;

implementation

function pgSpriteCreate(SpriteClass: TSpriteClass; AParent: TSprite; const SpriteName: string = ‘‘): TpgGUISprite;
begin
  Result := SpriteClass.Create(AParent);
  with TpgGUISprite(Result) do
  begin
    if ControlName <> ‘‘ then
      ControlName := SpriteName;
  end;
end;

function GenerateComponent(const ClassName: string; AParent: TSprite; const SpriteName: string = ‘‘): TpgGUISprite;
var
  mClass: TSpriteClass;
  mObj: TpgGUISprite;
begin
  Result := nil;
  mClass := TSpriteClass(GetClass(ClassName));
  if mClass = nil then exit
  else
  begin
    mObj := mClass.Create(AParent);
    TpgGUISprite(mObj).ControlName := SpriteName;
    Result := mObj;
  end;
end;

procedure initRegisterClasses;
var
  i: Integer;
  className: TPersistentClass;
begin
  for i:=Low(ClassArray) to High(ClassArray) do
  begin
    className:= ClassArray[i];
    RegisterClasses(className);
  end;
end;

procedure finaUnRegisterClass;
var
  i: Integer;
  className: TPersistentClass;
begin
  for i:=Low(ClassArray) to High(ClassArray) do
  begin
    className:= ClassArray[i];
    UnRegisterClass(className);
  end;
end;

initialization
  initRegisterClasses;
finalization
  finaUnRegisterClass;

end.

http://www.cnblogs.com/kfarvid/archive/2010/01/18/1651154.html

控件动态产生器(使用RegisterClasses提前进行注册)

标签:

原文地址:http://www.cnblogs.com/findumars/p/5951332.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!