Solved

Creating A User Profile as a static member of the document

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Pressing cancel button with C# UI Automation 3 81
method notes when mouse over in eclipse 5 87
wait notify demo infinite loop 3 124
mapAB Challlenge 35 156
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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

860 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