+ -
当前位置:首页 → 问答吧 → form的showmodal碰到的问题

form的showmodal碰到的问题

时间:2011-08-15

来源:互联网

form1上有一个Button1
uses unit2,unit3;
  button1.click事件调用form2  
  with tForm2.create(self) do 
  try 
  showmodal;
  finally 
  free;
  end;
   
form2上也有一个Button1
uses unit1,unit3;
  button1.click事件调用form3  
  with tForm3.create(self) do 
  try 
  showmodal;
  finally 
  free;
  end;

再建一form3,也放一button
uses unit2,unit1

button1.click事件中showmessage(form2.button1.caption)总是报access violation错误

但如果在form2上放一button ,click事件中showmessage(form1.button1.caption)不报错

这是什么原因呀,请问才能在form3中调用form2中组件的值 呢?

作者: n29882942   发布时间: 2011-08-15

我很好奇,你能够在再Form2上再创建一个Form3

作者: rainychan2009   发布时间: 2011-08-15

你把uses的位置放到implementation下面试下看,

还有应该就是和shomodal模式有关

作者: omagic   发布时间: 2011-08-15

因为Form1是主窗口,而Form2不是,你在建立时没有给Form2赋值,Form2为空指针。如改成:
Form2 := TForm2.Create(self);就可以了。

作者: Oraclers   发布时间: 2011-08-15

form1上有一个Button1
uses unit2,unit3;
  button1.click事件调用form2  
  with tForm2.create(self) do  
  try  
  showmodal;
  finally  
  free;
  end;



  with tForm2.create(self) do 这里建成的非FORM2这个变量

在FORM1里建FORM2,应该用 

  form2:= tform2.Create(nil);
  form2.ShowModal;
  form2.Free;

作者: dinoalex   发布时间: 2011-08-15

热门下载

更多