uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
StdCtrls, ExtCtrls, Buttons, Clipbrd, Comctrls, Db, Dbcgrids,
Dbctrls, Dbgrids, Dblookup, Dbtables, Ddeman, Dialogs,
Filectrl, Grids, Mask, Menus, Mplayer, Oleconst, Olectnrs,
Olectrls, Outline, Tabnotbk, Tabs;
type
TClassArray = array [1..107] of TPersistentClass;
// definition temporary used to check the data types
// TClassArray = array [1..107] of TComponentClass;
const
ClassArray: TClassArray = (
TApplication, TDDEServerItem, TPanel, TAutoIncField,
TDirectoryListBox, TPopupMenu, TBatchMove, TDrawGrid,
TPrintDialog, TBCDField, TDriveComboBox, TPrinterSetupDialog,
TBevel, TEdit, TProgressBar, TBitBtn,
TField, TQuery, TBlobField, TFileListBox,
TRadioButton, TBooleanField, TFilterComboBox, TRadioGroup,
TButton, TFindDialog, TReplaceDialog, TBytesField,
TFloatField, TCheckBox, TFontDialog,
TRichEdit, TColorDialog, TForm, TSaveDialog,
TComboBox, TGraphicField, TScreen, TCurrencyField,
TGroupBox, TScrollBar, TDatabase, THeader,
TScrollBox, TDataSource, THeaderControl, TSession,
TDateField, THotKey, TShape, TDateTimeField,
TImage, TSmallIntField, TDBCheckBox, TImageList,
TSpeedButton, TDBComboBox, TIntegerField, TStatusBar,
TDBCtrlGrid, TLabel, TStoredProc, TDBEdit,
TListBox, TStringField, TDBGrid, TListView,
TStringGrid, TDBImage, TMainMenu, TTabbedNotebook,
TDBListBox, TMaskEdit, TTabControl, TDBLookupCombo,
TMediaPlayer, TTable, TMemoField, TDBLookupComboBox,
TMemo, TTabSet, TDBLookupList, TTabSheet,
TDBLookupListBox, TMenuItem, TTimeField, TDBMemo,
TNotebook, TDBNavigator, TOleContainer, TTimer,
TDBRadioGroup, TOpenDialog, TTrackBar, TDBText,
TOutline, TTreeView, TDDEClientConv, TOutline,
TUpdateSQL, TDDEClientItem, TPageControl, TUpDown,
TDDEServerConv, TPaintBox, TVarBytesField, TWordField);
procedure GenerateComponent(AParent:TComponent;
AClass:String; //在这里代入你的Edit.Text
X,y:Integer);
var
MyClass:TComponentClass;
MyObj:TComponent;
begin
MyClass:=TComponentClass(GetClass(AClass));
if MyClass=nil then beep;
else
begin
MyObj:=MyClass.Create(AParent);
if MyObj.InheritsFrom(TControl) then
begin
TControl(MyObj).Left:=X;
TControl(MyObj).top:=Y;
TControl(MyObj).Parent:=AParent;
end;
end;
end;