Report由Frm_CountClothes启动,Report的Implementation段引用了一个Unit UntClothes, 在NeedData里,计算了nCol/nRow没错误:sValue:=UntClothes.frm_CountClothes.CenterGrid1.Cells[nCol,nRow];写代码过程中没有一点错误,一执行到这里就出错Read  xxx Access Error,为什么!!!简直疯了!

解决方案 »

  1.   

    我这样做的:主界面:uses UntCountClothes.......
    ......var
       frm_CountClothes:tFrm_CountClothes;
    Begin
       frm_CountClothes:=tFrm_CountClothes.Create(self);
       frm_CountClothes.Show;
    End;
    ....在FRM_CountCLothes:
    uses Rpt_Clothes.....
    ....Rpt_Clothes.PreviewModal;在程序的Initlize创建了rpt_CLothes的实例。
    这样做的其他地方都可以,只有这里很怪不行。现在解决了:
    在主单元UntMDI全部引用之,然后创建一个:
    var
       frm_Free:tForm;
    ......在打印调用:
    uses UntMDI;
    ....(UntMDI.frm_Free as UntCountClothes.tFrm_CountClothes).CenterGrid1.Cells[nCol,nRow];有什么更好的办法?谢谢各位。
      

  2.   

    我没太读懂,
    你在引用
    sValue:=UntClothes.frm_CountClothes.CenterGrid1.Cells[nCol,nRow];
    之前是否已经创建了frm_CountClothes???
    你可以在这句代码之前加行:showmessage(frm_CountClothes.name);试试
    上面的UntClothes可以去掉!
      

  3.   

    谢谢各位,我走了弯路,解决了。 一起看看代码到底怎么的,提高一下: 
    //原代码: 
    //主单元UntMDI,调用单元UntCountClothes,打印单元UntPrint2. 
    程序的Initlize中创建了RptPrint2的实例. 
    在UntMDI的菜单调用untCountClothes: 
    var 
       frm_CountClothes:tFrm_CountClothes; 
    begin 
       frm_CountCLothes:=tFrm_CountClothes.Create(self); 
       frm_CountClotehs.Show; 
    end; 
    //========在UntCountClothes中: 
    Uses UntPrint2; 
    ..... //打印 
    RptPrint2.Preview; 
    //==============在RptPrint2.中引用了UntCountClothes;他的OnNeedData: 
    sValue:=UntCountClothes.Frm_CountClothes.CenterGrid1.Cells[1,1]; 
    这里排除了cells下标超出,在写代码的过程中没有错误,但运行中就出错了。 
    但是 sValue:=UntCountClothes.Frp_CountClothes.Caption;就没错~~! //=====现在的解决办法: 
    在UntMDI中另外定义一个变量: 
    var 
       Frm_MDI:tFrm_MDI;  //主窗体 
       Frm_Free:tForm;    //备用 
    ........ 
    在菜单中调用: 
    var 
       frm_CountClothes:tFrm_CountClothes; 
    begin 
       frm_CountClothes:=tFrm_CountClothes.Create(self); 
       UntMDI.frm_Free:=frm_CountClothes; 
    end; 
    //在打印中引用UntMDI 
    sValue:=(UntMDI.frm_Free as UntCountCLothes.Tfrm_CountClothes).CenterGrid2.Cells[nCol,nRow]; 
    就行了,我也不明白怎么会这样~~~各位指教!