[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Global .NET Framework Objects

Posted on 2004-08-18
3
Medium Priority
?
410 Views
Last Modified: 2010-04-24
I just started playing around with the .NET VC++. I'm trying to make a string, or a pointer to a File object, global throughout a form. Whenever I try to do either, I get an error that says .NET Framework objects cannot be global. What I have is one button asks the user for the filename, and a completly different part of the code writes to that file, so I need a way to pass either the file name or a reference to a File object between the two. The button never calls the other function directly, as the other function is on a timer that runs at regular intervals, so I can't just pass the filename. Thanks.
0
Comment
Question by:jasoncout
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 48

Expert Comment

by:AlexFM
ID: 11830206
Keep .NET class instance as class member:

class SomeClass
{
    ...
    String* someString;
};

If you need to make it global (the only instance in the program), use static class member.
0
 

Author Comment

by:jasoncout
ID: 11830297
I get the same error when it is in a class. This is the exact error:

Form1.h(26): error C3145: 'captureFileName' : cannot declare a global or static managed type object or a __gc pointer

and the code:


namespace D2XX_GUI
{
      using namespace System;
      using namespace System::ComponentModel;
      using namespace System::Collections;
      using namespace System::Windows::Forms;
      using namespace System::Data;
      using namespace System::Drawing;

      static System::String *captureFileName;
               .
               .
               .



0
 
LVL 48

Accepted Solution

by:
AlexFM earned 500 total points
ID: 11830435
I don't see that captureFileName belongs to the class.

namespace D2XX_GUI
{
     using namespace System;
     using namespace System::ComponentModel;
     using namespace System::Collections;
     using namespace System::Windows::Forms;
     using namespace System::Data;
     using namespace System::Drawing;

    __gc  class SomeClass
    {


         static System::String *captureFileName;
     }


0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
In Easy String Encryption Using CryptoAPI in C++ (http://www.experts-exchange.com/viewArticle.jsp?aid=1193) I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

656 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