动态申请类问题
定义一个结构类型如下:
typedef struct
{//存储offset输入界面创建的控件
TLabel* lblPenNO;
TEdit* edtValue1;
TCSpinEdit* edtValue2;
TEdit* edtDenomin;
TComboBox* cbbYoffset;
}InputObj;
然后定义一个存放InputObj的数组:
InputObj* pInputObj[PHCOUNT] = {NULL}; //PHCOUNT:宏定义
动态申请结构中定义的控件:
1 pInputObj[i] = new InputObj();
2 pInputObj[i]->lblPenNO = new TLabel();
3 pInputObj[i]->edtValue1 = new TEdit();
4 pInputObj[i]->edtValue2 = new TCSpinEdit();
5 pInputObj[i]->edtDenomin = new TEdit();
6 pInputObj[i]->cbbYoffset = new TComboBox();
结果编译时,第一行正确,从第2到第6报错,不知为何。。。。
[解决办法]
VCL组件,必须要有个Owner,this就代表当前窗体