c++ - Parameters File to Store All Variables -


background: i've created application large preference dialog user can configure number of pages, each bunch of different settings. these settings in form of dropdowns , text boxes. want store of variables 1 massive "parameters.h" file can access them anywhere in application. each sub-page has it's own source , header file.

i'm having trouble pointers though. i'm not sure how reference parameters class. basically, application has 2 main components: main dialog , bunch of sub, child pages. main dialog sub-pages shown , hidden, based on page user chooses in listbox on left of main dialog.

i'm working 1 sub-page right now, , have following, when debug, i'm getting <badptr> on place. have simplified code, should enough figure out i'm doing wrong.

question: how point parameters class in each sub-dialog can store , use of these variables?


saprefsdialog.cpp: main dialog houses sub-pages

bool csaprefsdialog::oninitdialog()  {     cdialog::oninitdialog();     fsc_main fscmain;     fscmain.setparameterspointer(&m_pparams);     // [ ... ] } 

saprefsdialog.h: main dialog header file

#include "parameters.h"  public:     csaprefsdialog(cwnd* pparent = null);   // standard constructor    ~csaprefsdialog();      parameters m_pparams; 

fsc_main.h: sub-page header file

#include "parameters.h"  class fsc_main : public csaprefssubdlg { // construction public:     fsc_main(cwnd* pparent = null);   // standard constructor  // dialog data     //{{afx_data(fsc_main)     enum { idd = idd_fs_config_main };     //}}afx_data  public:      void setparameterspointer(parameters* pparameters)         { m_params = pparameters; }  private:     parameters *m_params; }; 

parameters.h

#include "stdafx.h" #include "prefs.h"  #pragma once  class parameters { public:         parameters();   // standard constructor public:     ~parameters(void);  protected:     virtual void dodataexchange(cdataexchange* pdx);    // ddx/ddv support  public:  //***************************************************************************** // // fsc_main.cpp variables // //*****************************************************************************      cstring m_strvehiclesmainnumvehicles;     cstring m_strvehiclesmainmaxsensorcount;     cstring m_strvehiclesmaintaskprocessinginterval;     cstring m_strvehiclesmain     // [ ... ] 

parameters.cpp

#include "stdafx.h" #include "prefs.h" #include "pages.h" #include "parameters.h"  //***************************************************************************** // // parameters::parameters // //*****************************************************************************  parameters::parameters():       m_strvehiclesmainnumvehicles("")     , m_strvehiclesmainmaxsensorcount("")     , m_strvehiclesmaintaskprocessinginterval("")     // [ ... ] { } 

the problem you're making pages local variables in csaprefsdialog::oninitdialog, , variables destroyed leave function. should make them member variables of csaprefsdialog class. else you're doing looks fine.


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -