jens_dalhoff
asked on
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
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
ASKER
Yes i have tried that and it asserts at line 215 doccore.cpp
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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.
ASKER
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?
Did you try CDocument::SetTitle() ?
If that doesn't work, get a pointer to the view and use SetWindowText() to set it yourself.
If that doesn't work, get a pointer to the view and use SetWindowText() to set it yourself.
ASKER
Thank you wayside - sorry i cant give you points because Zoppo answared my question..
have you tried 'SetPathName( "", FALSE ) ?
If this still asserts please tell where it assert (file, line) ...
ZOPPO