源码如下
//------------------调用程序----------------------
//传递path路径和字符串变量窗体名给过程
tabname:='frmkf'; //窗体名称
outfrmc(path,tabname);
//---执行程序------------------------------------------
{
如何才能通过变量得到窗体的frmkf.cxgrid1
请帮我改一下下面程序???
}
procedure Tfrmkf_outfile.outfrmc(ph,ft:string);
begin
ExportGrid4ToEXCEL(ph,Tform(ft).cxgrid1,True,True);
end;
//------------------调用程序----------------------
//传递path路径和字符串变量窗体名给过程
tabname:='frmkf'; //窗体名称
outfrmc(path,tabname);
//---执行程序------------------------------------------
{
如何才能通过变量得到窗体的frmkf.cxgrid1
请帮我改一下下面程序???
}
procedure Tfrmkf_outfile.outfrmc(ph,ft:string);
begin
ExportGrid4ToEXCEL(ph,Tform(ft).cxgrid1,True,True);
end;
或者使用TObject类的FieldAddress方法
ExportGrid4ToEXCEL(ph,Tform(FindComponent(ft)).cxgrid1,True,True);
例如: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;
X := TCxGrid(TForm(Application.FindComponent('frmkf')).FindComponent('CxGrid1'));
报内存错 read of address 00000010
TGrid(TCustomForm(FindControl(handle)).FindComponent('cxgrid1'))
对照一下窗体的名字和控件对象的名字,是不是与代码中的一致,注意大小写
另外,窗体frmkf在创建时,其Owner是Application吗?这个请查看一下自己的程序,
所以在过程中要找到父窗体的cxGrid1.
以下语句目的是要找出父窗体的cxGrid1
X := TCxGrid(TForm(Application.FindComponent('frmkf')).FindComponent('CxGrid1')); 不知各位有没更好办法,做个通用的将cxGrid导出excel的方法?
如果不明确XXXXXX,就是默认Self.FindComponent,那当然是当前窗体了
是这样子的
Application.FindComponent找到