首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

delphi函数参数有关问题

2013-03-04 
delphi函数参数问题如下:unit1中引用了unit2 unit3,unit2窗体类型TForm2,unit3窗体类型TForm3。现在unit1中

delphi函数参数问题
如下:
unit1中引用了unit2 unit3,unit2窗体类型TForm2,unit3窗体类型TForm3。现在unit1中要写一个打开窗体的函数


function TForm1.a(b : XX): TForm;
begin
  result := b.create(application);
end;

调用时TForm2 TForm3作为参数:

form2 := a(TForm2);
form3 := a(TForm3);

delphi中“类型”可以作为参数传给函数/过程吗?如果可以,XX应该怎么写?谢过
[解决办法]
可以
class of class

Tclass
[解决办法]
可以,就是所谓的“元类”,你看看Application.CreateForm
[解决办法]
才看懂问啥


Type
TMyForm = class of TForm;
type
  TForm1 = class(TForm)
......

function TForm1.a(b: TMyForm): TForm;
begin
  result := b.create(self);
end;

......
uses unit2 unit3;
.....
var
  f: TForm;
begin
  f := a(TForm2);
  f.Show;
  f := a(TForm3);
  f.Show;
end;

热点排行