标签:
代码 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