Click here to Skip to main content
15,916,371 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: query on dynamic_cast Pin
Cedric Moonen20-Nov-07 0:55
Cedric Moonen20-Nov-07 0:55 
AnswerRe: query on dynamic_cast Pin
Hamid_RT20-Nov-07 1:05
Hamid_RT20-Nov-07 1:05 
QuestionOn Edit box Pin
Chandrasekharan P19-Nov-07 23:41
Chandrasekharan P19-Nov-07 23:41 
AnswerRe: On Edit box Pin
toxcct19-Nov-07 23:51
toxcct19-Nov-07 23:51 
GeneralRe: On Edit box Pin
Chandrasekharan P19-Nov-07 23:54
Chandrasekharan P19-Nov-07 23:54 
GeneralRe: On Edit box Pin
toxcct20-Nov-07 0:00
toxcct20-Nov-07 0:00 
GeneralRe: On Edit box Pin
Chandrasekharan P20-Nov-07 0:08
Chandrasekharan P20-Nov-07 0:08 
GeneralRe: On Edit box Pin
Nelek20-Nov-07 4:35
protectorNelek20-Nov-07 4:35 
In this case, I would make a function validating every editbox content. And if all are ok, then return true.
If you have lot of EditBoxes (I have one dialog with 24 coloured comboboxes), you can make it dinamically. I put the example to NUM_EDITS different editboxes.
//CMyDialog.h
CEdit* m_aPEdits [NUM_EDITS];
.
//CMyDialog.cpp

void CMyEdit::OnInitDialog ()
{
   //More code

   m_aPEDits [0] = (CEdit*) GetDlgItem(IDC_MY_EDIT1);
   m_aPEDits [1] = (CEdit*) GetDlgItem(IDC_MY_EDIT2);
   m_aPEDits [2] = (CEdit*) GetDlgItem(IDC_MY_EDIT3);
   m_aPEDits [3] = (CEdit*) GetDlgItem(IDC_MY_EDIT4);
   //and so on

   //More code
}


//
BOOL CMyEdit::ValidateEditContents ()
{
   int nError = 0;

   for (int i = 0; i < NUM_EDITS; i++)
   {   int nTemp = -1;
       nTemp = itoa (m_aPEdits[i]->GetDialogText ());
       if ( ((10 * i) < nTemp) && (nTemp < (10 * (i+1))) )
          continue;

       nError++;  //This will execute only when the if is not being executed
   }

   if (!nError)
      return TRUE;

   return FALSE;
}

//
void CMyEdit::OnOK ()
{
   //More Code

   if (ValidateEditContents ())
      m_bDlgOK = TRUE;

   //More code
}


//And where you call the dialog...

void SomeClass::A_Function ()
{
    //More code


    CMyDialog newDlg;

EditStartLabel:
    if (IDCANCEL == newDlg.DoModal ())
       goto EditEndLabel;

    if (!newDlg.m_bDlgOK)
    {   MessageBox ("One of the edits has an invalid value, please correct it", "Error", MB_OK);
        goto EditStartLabel;
    }

    //The datas were OK
    //So you can bring them here and save, operate or do whatever you want
    //with the member variables, i.e. newDlg.m_nAnInt;

EditEndLabel:
    //here you can free memory
    //or do whatever you want to be executed ALL the times this function is called
    return;
}


I know that is not an elegant code, but it works perfectly. I won't probably use this structure in my next project or if i rewrite this one in the future, so any tip, correction, opinion... will be wellcome.

But to start getting the concept about data validation in a "simple" way I think is good

Hope it helps





Greetings.

--------
M.D.V. Wink | ;)

If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson

GeneralRe: On Edit box Pin
toxcct20-Nov-07 4:44
toxcct20-Nov-07 4:44 
JokeRe: On Edit box Pin
Nelek20-Nov-07 21:31
protectorNelek20-Nov-07 21:31 
GeneralRe: On Edit box Pin
toxcct20-Nov-07 21:38
toxcct20-Nov-07 21:38 
GeneralRe: On Edit box Pin
Nelek21-Nov-07 0:45
protectorNelek21-Nov-07 0:45 
GeneralRe: On Edit box Pin
David Crow20-Nov-07 2:42
David Crow20-Nov-07 2:42 
GeneralRe: On Edit box Pin
toxcct20-Nov-07 2:51
toxcct20-Nov-07 2:51 
AnswerRe: On Edit box Pin
Haroon Sarwar20-Nov-07 0:18
Haroon Sarwar20-Nov-07 0:18 
GeneralRe: On Edit box Pin
David Crow20-Nov-07 2:49
David Crow20-Nov-07 2:49 
GeneralRe: On Edit box Pin
Chandrasekharan P20-Nov-07 19:02
Chandrasekharan P20-Nov-07 19:02 
GeneralRe: On Edit box Pin
David Crow21-Nov-07 3:04
David Crow21-Nov-07 3:04 
QuestionRe: On Edit box Pin
David Crow20-Nov-07 2:45
David Crow20-Nov-07 2:45 
AnswerRe: On Edit box Pin
Chandrasekharan P20-Nov-07 18:11
Chandrasekharan P20-Nov-07 18:11 
GeneralRe: On Edit box Pin
David Crow21-Nov-07 3:06
David Crow21-Nov-07 3:06 
QuestionHow to insert an icon in dialogue box Pin
Shaiju Ayyappan19-Nov-07 22:52
Shaiju Ayyappan19-Nov-07 22:52 
AnswerRe: How to insert an icon in dialogue box Pin
Haroon Sarwar19-Nov-07 22:59
Haroon Sarwar19-Nov-07 22:59 
AnswerRe: How to insert an icon in dialogue box Pin
Hamid_RT20-Nov-07 0:40
Hamid_RT20-Nov-07 0:40 
QuestionHow to insert a Control Panel Icon in Edit box Pin
Shaiju Ayyappan19-Nov-07 22:44
Shaiju Ayyappan19-Nov-07 22:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.