首页 > 代码库 > 控件动态产生器(使用RegisterClasses提前进行注册)
控件动态产生器(使用RegisterClasses提前进行注册)
代码Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->unit pgDynamicGenerate;//动态产生器interfaceuses 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;implementationfunction 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提前进行注册)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。