Solved

Creating A User Profile as a static member of the document

Posted on 2003-10-31
5
211 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
  • 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

808 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