Solved

Global .NET Framework Objects

Posted on 2004-08-18
3
401 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
  • 2
3 Comments
 
LVL 48

Expert Comment

by:AlexFM
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

743 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now