Trouble with global strings

Hello All,

I wrote a proof of concept program in Visual Studio Express 2005 that would read a file in binary stream using the fstream function (brief excerpt)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
{
cout << "Enter file name to open:";
cin >> gamefile;
cout << "You entered:" << gamefile << '\n';

GameStream.open (gamefile.c_str(), ios::in | ios::out | ios::binary | ios::ate);
if( GameStream.is_open() )
	{
		// Confirm file open
		cout << "File found, Opening....\n";
		SaveSize = GameStream.tellg ();
		GameStream.seekg (0, ios::beg);
		cout << "File Size is: " << SaveSize << " bytes\n";
	}

so now I'm upping the interface to that of the win32 application forms. It seems WAY less confusing than trying to form design in the dark with MFC or ATL. I can actually draw the window, textboxes, etc in the form designer (and see how it looks) and not have to write message loops, or deal with other windows APIs directly. Despite the Rapid Application Development advantages, I now have to deal with managed C++ (.Net) syntax. In the code above I was able to access a stream and read small lengths of the binary file from it without issue. In the managed phase, I can't declare a global stream Stream^ GameStream; outside of the event handler, but it won't let me even declare a global array so that I can have the file data SOMEWHERE in NON-PRIVATE memory where I can read from pieces from it into textboxes on the form. Please help.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
private: System::Void openToolStripMenuItem_Click(System::Object^ /*sender*/, System::EventArgs^ /*e*/) {
			Stream^ GameStream;
			OpenFileDialog^ openFileDialog1 = gcnew OpenFileDialog;

			openFileDialog1->InitialDirectory = "c:\\";
			openFileDialog1->Filter = "All files (*.*)|*.*|gs* files (*.gs*)|*.gs*";
			openFileDialog1->FilterIndex = 2;
			openFileDialog1->RestoreDirectory = true;
			openFileDialog1->FileMode::Open;
			

			if ( openFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK )
				{
					if ( (GameStream = openFileDialog1->OpenFile()) != nullptr )
						{
							//Copy file name to string
							GameFile = Convert::ToString(openFileDialog1->FileName);

							GameStream->Close();}
Hi, I am also using VS 2005 for C++/CLI (.Net ) - what I have done is to declare such variables in the form definition section - private if they are just to be used within that form, public if they need to be used in other forms as well
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
public ref class Form1 : public System::Windows::Forms::Form
{
private:
   DataManager ^dataManager;
   ...   //My other private variables for use globaly IN THIS FORM
public:
   Currencies ^currency;
   ...   //my other public varaiables which can be used outside this form
   Form1(void)
   {
   ...
   }
protected:
   /// <summary>
   /// Clean up any resources being used.
   /// </summary>
   ~Form1()
   {
      if (components)
      {
         delete components;
      }
   }
//And all the declarations from the form designer...
private: System::Windows::Forms::Label^  label10;
private: System::Windows::Forms::TextBox^  DocumentTypeNameBx;
...


Note that occasionaly the form designer has a hicup and puts a component declaration in the middle of the code I have entered - it then refuses to compile until I move the offendign lines to the 'correct' place.
THANKS Faldrax!!! That totally worked. It now compiles without error or complaint. I felt I had tried declarations all over the form, but obviously never in the right spot.
Topic archived. No new replies allowed.