How set empty string with CDocument::SetPathName()

Hi

I want to initialize the pathname in CDocument, so that it is empty like when you havent saved a file yet. I have tried various things with SetPathName(string) where string is CString("") or const char *a[1] = "" and so on, but this gives a debug assertion failure! When pathname not have been set yet and you use GetPathName() it returns "" and it is exactly that i want is to do again (after a file have been saved and a new file without filename has been made)... Please help
jens_dalhoffAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
ZoppoConnect With a Mentor Commented:
hm ... ok, that's not nice, but the only way I see to do this is to
directly set 'm_strPathName' to "" ... I'm not sure if this can lead
to problems anywhere, but you can try ...

ZOPPO
0
 
ZoppoCommented:
Hi jens_dalhoff,

have you tried 'SetPathName( "", FALSE ) ?

If this still asserts please tell where it assert (file, line) ...

ZOPPO
0
 
jens_dalhoffAuthor Commented:
Yes i have tried that and it asserts at line 215 doccore.cpp
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
waysideCommented:
The code for CDocument::OnNewDocument() sets it directly:

BOOL CDocument::OnNewDocument()
{
#ifdef _DEBUG
  if(IsModified())
    TRACE(traceAppMsg, 0, "Warning: OnNewDocument replaces an unsaved document.\n");
#endif

  DeleteContents();
  m_strPathName.Empty();      // no path name yet
  SetModifiedFlag(FALSE);     // make clean

  return TRUE;
}


It looks like SetPathName() only gets called when opening an existing document or saving a document, and the only thing it really does is verify the file name fits in a MAX_PATH -sized array, and sets the window title to the name. So it should be safe enough to clear m_strPathName manually.
0
 
jens_dalhoffAuthor Commented:
Ok it almost works because the string is set to "" but in the top of the window the old filename still is displayed.. Normally it would say "Untitled" when you use "New File".. How can the filename be updated?
0
 
waysideCommented:
Did you try CDocument::SetTitle() ?

If that doesn't work, get a pointer to the view and use SetWindowText() to set it yourself.
0
 
jens_dalhoffAuthor Commented:
Thank you wayside - sorry i cant give you points because Zoppo answared my question..
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.