Note that there are some explanatory texts on larger screens.

plurals
  1. POParameters File to Store All Variables
    text
    copied!<p><strong>Background:</strong> So I've created an application that is basically a large preference dialog where the user can configure a number of pages, each with a bunch of different settings. These settings are in the form of dropdowns and text boxes. I want to store all of the variables into one massive "Parameters.h" file so that I can access them from anywhere in my application. Each sub-page has it's own source and header file.</p> <p>I'm having trouble with the pointers though. I'm not sure how to reference the Parameters class. Basically, my application has two main components: a main dialog and a bunch of sub, child pages. The main dialog is where the sub-pages are shown and hidden, based on what page the user chooses in a listbox on the left of the main dialog.</p> <p>I'm just working with one sub-page right now, and have the following, but when I debug, I'm getting &lt;BadPtr&gt; all over the place. I have greatly simplified the code, but it should be enough to figure out what I'm doing wrong.</p> <p><strong>Question:</strong> So how do I point to this Parameters class in each sub-dialog so that I can store and use all of these variables?</p> <hr> <p><strong>SAPrefsDialog.cpp: Main dialog that houses the sub-pages</strong></p> <pre><code>BOOL CSAPrefsDialog::OnInitDialog() { CDialog::OnInitDialog(); FSC_Main fscMain; fscMain.SetParametersPointer(&amp;m_pParams); // [ ... ] } </code></pre> <hr> <p><strong>SAPrefsDialog.h: Main dialog header file</strong></p> <pre><code>#include "Parameters.h" public: CSAPrefsDialog(CWnd* pParent = NULL); // standard constructor ~CSAPrefsDialog(); Parameters m_pParams; </code></pre> <hr> <p><strong>FSC_Main.h: Sub-page header file</strong></p> <pre><code>#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; }; </code></pre> <hr> <p><strong>Parameters.h</strong></p> <pre><code>#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 // [ ... ] </code></pre> <hr> <p><strong>Parameters.cpp</strong></p> <pre><code>#include "stdafx.h" #include "prefs.h" #include "pages.h" #include "Parameters.h" //***************************************************************************** // // Parameters::Parameters // //***************************************************************************** Parameters::Parameters(): m_strVehiclesMainNumVehicles("") , m_strVehiclesMainMaxSensorCount("") , m_strVehiclesMainTaskProcessingInterval("") // [ ... ] { } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload