Solved

Global .NET Framework Objects

Posted on 2004-08-18
3
408 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 125 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

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 is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

729 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