My question is logical rather than syntactic. Purpose: get and save parameters from (c) xml

Wrote this class:

.h

using namespace System::Xml::Linq; /* ЧТЕНИЕ ИЗ XML */ public ref class MBdat{ private: bool access = false; PathCombiner^ get; XElement^ options; public: bool access_MBdat(); String^ load(String^ option); void save(String^ option, String^ value); }; 

.cpp

 #include "native.h" #include "base.h" bool MBdat::access_MBdat(){ try { options = XElement::Load(get->MBdat()); access = true; } catch (Exception^ e) { access = false; MessageBox::Show(e->ToString()); } return access; } String^ MBdat::load(String^ option){ String^ value = ""; access_MBdat(); if (access) value = options->Element(option)->Value; return value; } void MBdat::save(String^ option, String^ value){ access_MBdat(); if (access) { options->Element(option)->Value = value; options->Save(get->MBdat()); } else { MessageBox::Show("Сохранение изменённых параметров не возможно, нет доступа к файлу настроек"); } } 

When try is executed in access_MBdat (), the program goes to MessageBox catch: The object reference does not indicate an object instance. This means that you need to declare options correctly (gcnew XElement ("container")), but this is not a task, with such a construction, the options in the class should be global, and therefore I cannot immediately declare it with a link to the file, because I want to handle possible errors ( bloody level of user rights to access files, especially in Program Files.) Help with ideas?

  • forgot to specify, PathCombiner is my class, there I get the absolute path ... - Smirnov
  • Hmm, but remind get->MBdat() , what does get->MBdat() mean? - VladD
  • Because it falls, apparently, it is this expression. - VladD
  • get-> MBdat () = c: \ document.xml - Smirnov
  • Okay, what kind of string falls? If get->MBdat() does not fall, and XElement::Load does not fall (should not), then where does the exception come from? - VladD

0