Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

CNINumEdit invalid pointer

I have a dialog with a CNINumEdit control on it. When I call the dialog and try to call SetValue() on this control, the application throws an assert and gives me an invalid pointer error. Can anyone tell me why? Here is the code:

void CTIMS_03View::OnSetupAcquisitionparameters()
{
CAcqParamDialog dlg(this);
CTIMS_03Doc *pDoc = GetDocument();
// Read the number of masses in program.
dlg.m_NumMasses.SetValue((double)pDoc->PLocalAcqParams->PTheProgramSet->Number_of_Masses);

The application fails on the last line listed. I am using Measurement Studio with Visual C++ 6.0 SP5.
0 Kudos
Message 1 of 6
(3,457 Views)
Hello

Is pDoc->PLocalAcqParams->PTheProgramSet->Number_of_Masses a valid pointer? Try doing something like TRACE (pDoc->PLocalAcqParams->PTheProgramSet->Number_of_Masses) and see if you get the same error. Just to check if the value you are passing it is valid.

Bilal Durrani
NI
Bilal Durrani
NI
0 Kudos
Message 2 of 6
(3,457 Views)
It is a valid value. I don't get the any errors when running a trace against the pointer. I think the problem may stem from the CNiNumEdit object not being instantiated when I am trying to access it, but I don't have the foggiest clue how to go about checking this. The problem only happens when I try to set the value for the CNiNumEdit control. If I comment that line out, it runs to the end of the function.
0 Kudos
Message 3 of 6
(3,457 Views)
I suggest adding another constructor to your dialog class that takes an initial value, instantiate the dialog with that constructor and save the value, then override OnInitDialog and set the value there. For example:

// In AcqParamDialog.h
class CAcqParamDialog : public CDialog
{
public:
CAcqParamDialog(CWnd* pParent = NULL);
CAcqParamDialog(double initialValue, CWnd* pParent = NULL);

BOOL OnInitDialog();

// Dialog Data
//{{AFX_DATA(CAcqParamDialog)
enum { IDD = IDD_ACQPARAMDIALOG };
CNiNumEdit m_NumMasses;
//}}AFX_DATA

// ...

private:
double m_initialValue;
};

// In AcqParamDialog.cpp
CAcqParamDialog::CAcqParamDialog(double initialValue, CWnd* pParent /*=NULL*/)
: CDialog(CAcqParamDialog
::IDD, pParent), m_initialValue(initialValue)
{
}

BOOL CAcqParamDialog::OnInitDialog()
{
CDialog::OnInitDialog();
m_NumMasses.SetValue(m_initialValue);

return TRUE;
}

// ...

Then you can use this class like this:

double initialValue = (double)pDoc->PLocalAcqParams->PTheProgramSet->NumberOfMasses;
CAcqParamDialog dlg(initialValue, this);
// ...

This should let you show the dialog with the desired initial value without any problems. Please give this a try and see how it works out.

- Elton
Message 4 of 6
(3,457 Views)
Could you post a small sample of this problem? I would like to try it out on my machine.

Thanks
Bilal Durrani
NI
0 Kudos
Message 5 of 6
(3,457 Views)
Worked like a charm. Thank you very much!!
0 Kudos
Message 6 of 6
(3,457 Views)