源码如下
//------------------调用程序----------------------
//传递path路径和字符串变量窗体名给过程
tabname:='frmkf'; //窗体名称
outfrmc(path,tabname);
//---执行程序------------------------------------------
{
如何才能通过变量得到窗体的frmkf.cxgrid1
请帮我改一下下面程序???
}
procedure Tfrmkf_outfile.outfrmc(ph,ft:string);
begin
ExportGrid4ToEXCEL(ph,Tform(ft).cxgrid1,True,True);
end;

解决方案 »

  1.   

    使用TComponent类的FindComponent方法
    或者使用TObject类的FieldAddress方法
      

  2.   

    试下
    ExportGrid4ToEXCEL(ph,Tform(FindComponent(ft)).cxgrid1,True,True); 
      

  3.   


    例如:procedure Tfrmkf_outfile.outfrmc(ph,ft:string); 
    var
      X : TCxGrid;
    begin
      X := TCxGrid(TForm(Application.FindComponent('frmkf')).FindComponent('CxGrid1')); 
      ExportGrid4ToEXCEL(ph,X,True,True); 
    end; 
      

  4.   


      X := TCxGrid(TForm(Application.FindComponent('frmkf')).FindComponent('CxGrid1')); 
     报内存错 read of address 00000010 
      

  5.   

    handle:=Findwindow('Tfrmkf',Pchar('frmkf'));//获取窗体句丙
    TGrid(TCustomForm(FindControl(handle)).FindComponent('cxgrid1'))
      

  6.   


    对照一下窗体的名字和控件对象的名字,是不是与代码中的一致,注意大小写
    另外,窗体frmkf在创建时,其Owner是Application吗?这个请查看一下自己的程序,
      

  7.   

    我想实现的功能是建一个公用的导出窗体,任何父窗体都可创建并调用该窗体的导出过程.
    所以在过程中要找到父窗体的cxGrid1.
    以下语句目的是要找出父窗体的cxGrid1
    X := TCxGrid(TForm(Application.FindComponent('frmkf')).FindComponent('CxGrid1')); 不知各位有没更好办法,做个通用的将cxGrid导出excel的方法?
      

  8.   

    经过测试,FindComponent只能找到当前窗体内的组件。不能找到父窗体组件。
      

  9.   

    XXXXXX.FindComponent
    如果不明确XXXXXX,就是默认Self.FindComponent,那当然是当前窗体了
      

  10.   

    FindComponent只能找到当前窗体内的组件。不能找到父窗体组件。
    是这样子的 
      

  11.   

    看清楚,前面代码中有Application的应用,对于Application来讲,所有Owner为Application的窗体实例,都可以用
    Application.FindComponent找到