procedure TForm15.BitBtn4Click(Sender: TObject);
var
formclass:Tformclass;
begin
formclass:=Tformclass(getclass('form16'));
with formclass.Create(application) as TForm do
~~~~~~~~~~ *********
begin
QuickRep1.preview;//运行时候出错~~
end;
end;
var
formclass:Tformclass;
begin
formclass:=Tformclass(getclass('form16'));
with formclass.Create(application) as TForm do
~~~~~~~~~~ *********
begin
QuickRep1.preview;//运行时候出错~~
end;
end;
出错信息:
[Error] print.pas(41): Undeclared identifier: 'QuickRep1'备注:
QuickRep1 是form16上的打印控件~~
你确定没搞错,我看应该是编译时就出错才对。你的语句前并没有指明这个QUICKREP1是谁的,当然是Undeclared identifier了。
TformClass是窗体类的引用类,简单的说它创建的窗体在代码中只能调用基累
Tform的属性和方法,而form16是从Tform继承下来的子类,然后它自己添加了一个成员quickrep1,这个属性只能由Tform16来显示访问。
你只能这样写var
formclass:Tformclass;
begin
formclass:=Tformclass(getclass('form16'));
with formclass.Create(application) as TForm16(改这里) do
~~~~~~~~~~ *********
begin
QuickRep1.preview;//运行时候出错~~
end;
end;当然,这样改就失去了这个函数的意义,不过没有别的办法。
或者你在定义一个基类的引用类,然后在这个基类里添加一个虚拟函数。
然后你的form16什么的都从这个基类继承,并实现这个虚拟函数。然后
你就可以用类似你的创建和调用写法了。如果你比较生疏的话,建议多看看OOP的资料。
Tform16。
var
formclass:Tformclass;
begin
formclass:=Tformclass(getclass('form16'));
with formclass.Create(application) as TForm do
~~~~~~~~~~ *********
begin
QuickRep1.preview;//运行时候出错~~
end;
end;