我做一个窗体显示函数,提示错误,高手帮我看一下,一定发分(100分)

  • 主题发起人 主题发起人 wecap
  • 开始时间 开始时间
W

wecap

Unregistered / Unconfirmed
GUEST, unregistred user!
function Tlzgdata.showform(inpurform: tformclass): boolean;
var b_tinpurform:inpurform;
begin
try
b_tinpurform=tinpurform.create(nil);
b_tinpurform.show;
finally
b_tinpurform.free;
end;
end;
 
function Tlzgdata.showform(inpurform: tformclass): boolean;
var b_tinpurform:inpurform;
begin
try
if not Assigned(b_tinpurform) then
b_tinpurform:=tinpurform.create(nil);
b_tinpurform.showmodal;
finally
FreeAndNil(b_tinpurform);
end;
end;

 
function Tlzgdata.showform(inpurform: tformclass): boolean;
var b_tinpurform:inpurform;
begin
try
b_tinpurform=tinpurform.create(application);
b_tinpurform.show;
b_tinpurform.update;
Sleep(1000);
finally
b_tinpurform.free;
end;
end;
 
function Tlzgdata.showform(inpurform: tformclass): boolean;
var
b_tinpurform:tform;
begin
try
b_tinpurform:=tformclass.create(nil);
b_tinpurform.show;
finally
b_tinpurform.free;
end;
end;
 
function Tlzgdata.showform(inpurform: tformclass): boolean;
var
b_tinpurform:tform;
begin
try
b_tinpurform:=inpurform.create(nil);
b_tinpurform.show;
finally
b_tinpurform.free;
end;
end;

 
//窗体不用SHOWMODAL
Application.CreateForm(TFormWait, FormWait);
try
With FormWaitdo

begin

show;
Update;
end;

//在这里写你要做的事情
with FormWaitdo

begin

Hide;
Update;
end;

finally
FormWait.free;
end;
 
以上代码我试了,不行呀,你样试过没有哟
 
我的试了有什么地方不行?说清楚些?
 
function Tlzgdata.showform(inpurform: tformclass): boolean;
var b_tinpurform:inpurform;
begin
try
b_tinpurform=tinpurform.create(nil);
b_tinpurform.showmodal;
finally
b_tinpurform.free;
end;
end;
 
是呀,我的也是试过了的。
只是不太清楚你想怎样,要达到什么效果,你的程序是怎样不行的,有什么提示?
说清楚,我们才好回答
 
function Tform1.showform(inpurform: tformclass): boolean;
var b_tinpurform:Tform;
begin
try
b_tinpurform:=inpurform.create(nil);
b_tinpurform.showmodal;
finally
b_tinpurform.free;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
showform(tformclass(form2.ClassType));
end;
 
先指出你的错误之处
function Tlzgdata.showform(inpurform: tformclass): boolean;
var b_tinpurform:inpurform;
begin
try
//b_tinpurform=tinpurform.create(nil);//错误在这里,用下面一句
b_tinpurform:=tinpurform.create(nil);//记住了,少了:号
b_tinpurform.show;
finally
b_tinpurform.free;
end;
end;
不知道楼主为会什么要这样写,这样不好吗
function Tlzgdata.showform(inpurform: tformclass): boolean;
begin
with inpurform.create(nil)do
try
showmodal;
finally
free;
end;
end;

function Tlzgdata.showform(inpurform: tformclass): boolean;
begin
with inpurform.create(nil)do
try
showm;
//干其它的活吧
finally
free;
end;
end;
尽量做到不用变量的地方,坚决不用,浪费资源嘛
 
procedure CreateModalForm(TMyForm:TFormClass;MyForm:TForm);
begin
screen.cursor:=crhourglass;
try
MyForm:=TMyForm.create(application);
screen.cursor:=crdefault;
finally
MyForm.showmodal;
end;
end;
 
在Create之前加一个if not Assigned(b_tinpurform) then
 
function Tlzgdata.showform(inpurform: tformclass): boolean;
var b_tinpurform:inpurform;
begin
//try 注释掉这一句
b_tinpurform[red]:=[/red]tinpurform.create(nil);//这里少了冒号
try //把try放到这里来
b_tinpurform.show;
finally
b_tinpurform.free;
end;
end;

你先前的try finally块包含了create构造函数,要知道,这个构造函数会失败的,如果失败,你的程序仍然将跳到finally会里面去执行b_tinpurform.free语句,要知道,这时b_tinpurform不是一个有效的指针,你的任何试图访问该变量的成员的动作都将触发异常!就是最讨人厌的那个指针异常!
所以,try finally不要包含create构造函数,而 应该是create构造函数后面紧跟的一行。
还有,你的代码如果按照我说的写了仍然有问题,那么问题不在你的这个function Tlzgdata.showform(inpurform: tformclass): boolean;方法里面,而是很有可能在你的Tb_tinpurform类里面的构造函数、析构函数、OnCreate事件、OnShow事件、OnClose事件、OnDestroy事件里面,查查这些代码有没有不对的地方。或者干脆,单步运行,跟进去看看就知道错误在哪里了。
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
732
import
I
后退
顶部