Solved

Creating A User Profile as a static member of the document

Posted on 2003-10-31
5
215 Views
Last Modified: 2013-11-20
I have a program for which I want to create a user profile. My best gues is that I should make it a static member of the document, because I have MDI and they all will want the same preferences. The thing is, I want the user to be able to set the preferences even if a document is not open. If my memory serves me correctly...an instance of an object does not have to be created in order to set static members. Am I correct in assuming this? So when my program launches...I can load them before a document is instantiated. Where would be the most appropriate place to do something like this????
0
Comment
Question by:SGyves
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 400 total points
ID: 9660374
I guess you are loading the user profile when your application starts, so 'InitInstance()' seems a good place for me. However, I'd refrain from using static members, adding the profile to the Application 'feels' better to me, e.g.

CUserProfile {

  ///...
};

CMyApp : public CWinApp {

public:

CUserProfile* GetUserProfile (); // call this one from your docs
BOOL LoadUserProfile (); // call that in 'InitInstance()'
}

// in the docs

CMyApp* pApp = ( CMyApp*) AfxGetApp ();

CUserProfile* pProf = pApp->GetProfile ();
0
 
LVL 86

Expert Comment

by:jkr
ID: 9660447
BTW, the 'static member' approach would work the same way:

// make sure this is a 'public' member - this is why the other approach 'feels' better.
CMyDoc::s_pProfile = NULL;

BOOL CMyApp::LoadUserProfile () { // call that in 'InitInstance()'

  // ....

  // on success:
  CMyDoc::s_pProfile = &m_profile;

}


0
 

Author Comment

by:SGyves
ID: 9660691
Ok...I see your point....it does seem more logical to have a member in the App. Thanks for the tip and the answer.
0
 

Author Comment

by:SGyves
ID: 9661150
Hey...can I use my Profile class' Serialize object to save and load it from disk...for example if I save it in a "userprof.dat" file...can I do it that way.
0
 

Author Comment

by:SGyves
ID: 9661173
Never mind...figured it out:

For example:

CFile myFile("myfile.dat", CFile::modeCreate | CFile::modeReadWrite);
CAge  age(21), *pAge;

// Create a storing archive.
CArchive arStore(&myFile, CArchive::store);

// Write the object to the archive
arStore.WriteObject( &age );

// Close the storing archive
arStore.Close();

// Create a loading archive.
myFile.SeekToBegin();
CArchive arLoad(&myFile, CArchive::load);

// Verify the object is in the archive.
pAge = (CAge*) arLoad.ReadObject( RUNTIME_CLASS(CAge) );
ASSERT( age == *pAge );
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question