form2,form3为动态创建的窗体,form3由form2一个button动态产生.form2里有一个label1,form3里有一个label1
在form3中,如果有label1.caption:='sfsdfds'没有错误,但如果是form3.label1.caption:='sfsdfsd'或form2.label1.caption:='sfsdfsd'
就有错,并有诸如此类的提示"access villation at 
address 0044AF58 in module "sfaproject.ext" Read of address 00000048". 为何这样?
如何做才能可以form3.label1.caption:='sfsdfsd'或form2.label1.caption:='sfsdfsd'不会错? 在线等...

解决方案 »

  1.   

    是不是放在private或protected中..
    还有就是有没有USES那个UNIT
      

  2.   

    没猜错的话!你的代码是这样写的var
      Form2:TForm2;
    begin
    Form2:=TForm2.Create(Application);
    Form2.Show;
    end;由于变量的作用域问题,单元Unit2中的Form2和这里的Form2并不同,Unit2中的Form2实例不是没生成吗?
      

  3.   

    ehom(?!)  多谢你.
    你说得很对, 准备接分. 
    另我想问下, 我是这样释放窗体的:
    onclose里:action:=cafree;
    ondestroy里:form2:=nil;不知对不对, 你是点做的?
      

  4.   

    当然可以,但如果这个窗体需要多次调用没必要释放!这样改下if not Assigned(Form2) then Form2:=TForm2.Create(Application); 另外Form2在单元Unit2中已经定义,没必要重复定义一全局变量!