根据.DFM文件动态生成窗体之前要先注册窗体中使用到的类。
在脚本中要使用窗体中的控件对象之前也要先注册这些控件对象。
unit UClass;
{$DEFINE EHLIB}
{$DEFINE RAIZE}
{$DEFINE DBANYWHERE}
{$DEFINE TMS}
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls, Contnrs,
ActiveX,
ActnList,
ADODB, DB,
Buttons,
Clipbrd,
CommCtrl,
ComObj,
ComServ,
DateUtils,
DBCtrls,
DBGrids,
DBTables,
ExtCtrls,
Grids,
IniFiles,
Isapi,
Isapi2,
Mask,
Math,
Menus,
Midas,
MMSystem,
MPlayer,
msxml,
OleDB,
OpenGL,
Printers,
Registry,
RichEdit,
ScktComp,
ShellAPI,
ShlObj,
SvcMgr,
SyncObjs,
UrlMon,
WinInet,
WinSock,
WinSpool
{$IFDEF RAIZE}
,rzedit
,rzpanel
,rzdbedit
,rzbtnedt
,rzsplit
,rzgrids
,rzbutton
,rztray
,rzbhints
,rzdbgrid
,rzdbcmbo
{$ENDIF}
{$IFDEF EHLIB}
,DBGridEh
,PrnDbgeh
{$ENDIF}
{$IFDEF TMS}
,atPascal
,atScript
{$ENDIF}
{$IFDEF DBANYWHERE}
,remoteStoredProc
,remoteupdateSql
,remoteUdpDataset
,remoteudpconnection
,applicationupdate
,remotetcpconnection
{$ENDIF}
,XPMan
;
procedure RegClass; // 注册支持的类别
procedure LoadFromDFM(const DFMname: string; Sender: TComponent); // 装载DFM脚本生成界面
procedure PianLiComps(Owner: TComponent; scripter: TatPascalScripter); // 遍历所有控件,脚本加载之
var
ClassArr: Array[0..85] of TPersistentClass;
implementation
procedure PianLiComps(Owner: TComponent; scripter: TatPascalScripter);
var
i, t: Integer;
begin
if owner = nil then exit;
for i := 0 to Owner.ComponentCount - 1 do
begin
scripter.AddComponents(Owner.Components[i]);
if (Owner.Components[i] is TPanel) or (Owner.Components[i] is TScrollBox)
then
if TWinControl(Owner.Components[i]).ControlCount > 1 then
for t := 0 to TWinControl(Owner.Components[i]).ControlCount - 1 do
Scripter.AddComponents(TWinControl(Owner.Components[i]).Controls[t]);
end;
end;
procedure RegClass;
begin
ClassArr[0] := TAnimate;
ClassArr[1] := TButton;
ClassArr[2] := TCheckBox;
ClassArr[3] := TColorDialog;
ClassArr[4] := TComboBox;
ClassArr[5] := TComboBoxEx;
ClassArr[6] := TCommonCalendar;
ClassArr[7] := TCommonDialog;
ClassArr[8] := TCoolBand;
ClassArr[9] := TCoolBands;
ClassArr[10] := TCoolBar;
ClassArr[11] := TDateTimePicker;
ClassArr[12] := TEdit;
ClassArr[13] := TFindDialog;
ClassArr[14] := TFontDialog;
ClassArr[15] := TForm;
ClassArr[16] := TFrame;
ClassArr[17] := TGroupBox;
ClassArr[18] := THeaderControl;
ClassArr[19] := TImageList;
ClassArr[20] := TLabel;
ClassArr[21] := TListBox;
ClassArr[22] := TListItem;
ClassArr[23] := TListView;
ClassArr[24] := TMemo;
ClassArr[25] := TMonthCalendar;
ClassArr[26] := TOpenDialog;
ClassArr[27] := TPageControl;
ClassArr[28] := TPageScroller;
ClassArr[29] := TPrintDialog;
ClassArr[30] := TProgressBar;
ClassArr[31] := TRadioButton;
ClassArr[32] := TReplaceDialog;
ClassArr[33] := TRichEdit;
ClassArr[34] := TSaveDialog;
ClassArr[35] := TScrollBar;
ClassArr[36] := TScrollBox;
ClassArr[37] := TStaticText;
ClassArr[38] := TStatusBar;
ClassArr[39] := TStatusPanel;
ClassArr[40] := TTabControl;
ClassArr[41] := TTabSheet;
ClassArr[42] := TToolBar;
ClassArr[43] := TToolButton;
ClassArr[44] := TTrackBar;
ClassArr[45] := TTreeNode;
ClassArr[46] := TTreeView;
ClassArr[47] := TUpDown;
ClassArr[48] := TPanel;
ClassArr[49] := TBitBtn;
CLassArr[50] := TShape;
ClassArr[51] :=TRadioGroup;
ClassArr[52] :=TImage;
ClassArr[53] :=TMediaPlayer;
ClassArr[54] :=TPaintBox;
ClassArr[55] :=TSpeedButton;
ClassArr[56] :=TMainMenu;
ClassArr[57] := TMenuItem;
ClassArr[58] := TDBGrid;
ClassArr[59] := TDBNavigator;
ClassArr[60] := TDataSource;
ClassArr[61] := TADOTable;
ClassArr[62] := TDBGridEh;
ClassArr[63] := TPrintDBGridEh;
ClassArr[64] := TRzPanel;
ClassArr[65] := TRzToolbar;
ClassArr[66] := TRzStatusBar;
ClassArr[67] := TRzButtonEdit;
ClassArr[68] := TRzEdit;
ClassArr[69] := TRzDBEdit;
ClassArr[70] := TRzButton;
ClassArr[71] := TRzBitBtn;
ClassArr[72] := TRzTrayIcon;
ClassArr[73] := TRzBalloonHints;
ClassArr[74] := TRzStringGrid;
ClassArr[75] := TRzDBGrid;
ClassArr[76] := TRzDBComboBox;
ClassArr[77] := TRemoteTCPConnection;
ClassArr[78] := TRemoteUdpConnection;
ClassArr[79] := TRemoteUdpDataSet;
ClassArr[80] := TRemoteUpdateSql;
ClassArr[81] := TApplicationUpdate;
ClassArr[82] := TRemoteStoredProc;
ClassArr[83] := TADOQuery;
ClassArr[84] := TADOConnection;
ClassArr[85] := TXPManifest;
RegisterClasses(ClassArr);
end;
procedure LoadFromDFM(const DFMname: string; Sender: TComponent); //根据.DFM文件动态生成窗体
var
DFMStream: TFileStream;
BinStream: TMemoryStream;
begin
DFMStream := TFileStream.Create(DFMname, fmOpenRead);
BinStream := TMemoryStream.Create;
try
ObjectTextToBinary(DFMStream, BinStream);
BinStream.Position := 0;
BinStream.ReadComponent(Sender);
finally
DFMStream.Free;
BinStream.Free;
end;
end;
initialization
RegClass;
finalization
UnRegisterClasses(ClassArr);
end.