原来回答过的问题:
如果不明白下面的代码,可以仔细看这个帖子:
http://www.delphibbs.com/delphibbs/dispq.asp?lid=3260876
根据字符动态创建form并在listview里显示一个节点,然后双击该节点显示该form
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, OleCtrls, ShockwaveFlashObjects_TLB, AppEvnts, StdCtrls,
ComCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
ListView1: TListView;
procedure ListView1DblClick(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
TClassArray = array [1..5] of TPersistentClass;
var
Form1: TForm1;
implementation
uses Unit2,unit3,unit4,unit5,unit6;
{$R *.dfm}
const
formarray: TClassArray = (tform2,tform3,TForm4,tform5,tform6);
procedure TForm1.ListView1DblClick(Sender: TObject);
begin
if ListView1.Selected<>nil then
if assigned(ListView1.Selected.Data) then
Tform(ListView1.Selected.Data).Show;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
item:Tlistitem;
frm:Tform;
i:integer;
k:boolean;
pc:TPersistentClass;
begin
try
pc:=findclass(edit1.Text);
except
showmessage('未找到类型'+edit1.Text);
exit;
end;
k:=false;
for i:=0 to application.ComponentCount-1 do
if uppercase(application.Components.ClassName)=uppercase(edit1.Text) then
begin
frm:=Tform(application.Components);
k:=true;
break;
end;
if not k then
application.CreateForm(TComponentclass(pc),frm);
showmessage(frm.ClassName);
item:=ListView1.Items.Add;
item.Caption:=edit1.Text;
item.Data:=frm;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
RegisterClasses(formarray);
end;
end.