Click here to Skip to main content
15,890,690 members
Home / Discussions / Managed C++/CLI
   

Managed C++/CLI

 
QuestionAccess controls from other modules of a program Pin
eugk12-Aug-07 23:31
eugk12-Aug-07 23:31 
AnswerRe: Access controls from other modules of a program Pin
mid=574113-Aug-07 5:38
mid=574113-Aug-07 5:38 
GeneralRe: Access controls from other modules of a program Pin
eugk13-Aug-07 8:40
eugk13-Aug-07 8:40 
GeneralRe: Access controls from other modules of a program Pin
mid=574113-Aug-07 9:12
mid=574113-Aug-07 9:12 
GeneralRe: Access controls from other modules of a program Pin
eugk13-Aug-07 12:02
eugk13-Aug-07 12:02 
GeneralRe: Access controls from other modules of a program [modified] Pin
mid=574113-Aug-07 12:35
mid=574113-Aug-07 12:35 
GeneralRe: Access controls from other modules of a program Pin
eugk13-Aug-07 15:52
eugk13-Aug-07 15:52 
GeneralRe: Access controls from other modules of a program [modified] Pin
mid=574113-Aug-07 16:12
mid=574113-Aug-07 16:12 
You are definitely doing too much regarding Question #1. You don't need to create an object every time you need to fire an event. I'm sorry my example code wasn't better. I just typed it into a text editor. I should have grabbed it from a working project.

Regarding Question #2, there's definitely a better way. I just stuck everything into one place for simplicity. I'd only confuse you more if I tried to describe a better way, so I'll make a working example in C++/CLI and send that to you.


-- modified at 22:39 Monday 13th August, 2007

To be a little clearer and more correct, here's the form class with irrelevant stuff stripped out:
#include "WorkerClass.h"

namespace WinApp1
{
   public ref class Form1 : public Form
   {
   public:

      Form1()
      {
         InitializeComponent();

         workerClass_ = gcnew WorkerClass();

         workerClass_->OnUpdateText += gcnew UpdateText( this, &Form1::UpdateTextHandler );
      }

   private:

      TextBox^ textBox_;
      Button^ button_;

      WorkerClass^ workerClass_;

      void button__Click( System::Object^ sender, System::EventArgs^ e )
      {
         workerClass_->DoSomething();
      }

      void UpdateTextHandler( String^ text )
      {
         textBox_->Text = text;
      }
   };
}
And, in another file called WorkerClass.h, here's WorkerClass, which was SomeClass in my previous example:
namespace WinApp1
{
   delegate void UpdateText( String^ );

   ref class WorkerClass
   {
   public:

      event UpdateText^ OnUpdateText;

      void DoSomething()
      {
         ++serialNumber_;
         OnUpdateText( Convert::ToString( serialNumber_ ) );
      }

   private:

      int serialNumber_;
   };
}
You don't need to derive your class from WorkerClass. All you need is an event of type UpdateText^ to which Form1 can attach a handler.
GeneralRe: Access controls from other modules of a program Pin
eugk13-Aug-07 20:26
eugk13-Aug-07 20:26 
QuestionWhat makes a class IDisposable? Pin
mid=574111-Aug-07 15:19
mid=574111-Aug-07 15:19 
AnswerRe: What makes a class IDisposable? Pin
Mark Salsbery12-Aug-07 7:30
Mark Salsbery12-Aug-07 7:30 
GeneralRe: What makes a class IDisposable? Pin
mid=574112-Aug-07 7:58
mid=574112-Aug-07 7:58 
GeneralRe: What makes a class IDisposable? Pin
Luc Pattyn12-Aug-07 8:41
sitebuilderLuc Pattyn12-Aug-07 8:41 
GeneralRe: What makes a class IDisposable? [modified] Pin
mid=574112-Aug-07 9:00
mid=574112-Aug-07 9:00 
GeneralRe: What makes a class IDisposable? Pin
iddqd51513-Aug-07 6:06
iddqd51513-Aug-07 6:06 
GeneralRe: What makes a class IDisposable? Pin
mid=574113-Aug-07 6:15
mid=574113-Aug-07 6:15 
GeneralRe: What makes a class IDisposable? Pin
led mike13-Aug-07 6:28
led mike13-Aug-07 6:28 
GeneralRe: What makes a class IDisposable? Pin
mid=574113-Aug-07 6:46
mid=574113-Aug-07 6:46 
GeneralRe: What makes a class IDisposable? Pin
iddqd51513-Aug-07 6:29
iddqd51513-Aug-07 6:29 
GeneralRe: What makes a class IDisposable? Pin
mid=574113-Aug-07 6:45
mid=574113-Aug-07 6:45 
GeneralRe: What makes a class IDisposable? Pin
iddqd51513-Aug-07 7:32
iddqd51513-Aug-07 7:32 
GeneralRe: What makes a class IDisposable? Pin
mid=574113-Aug-07 7:53
mid=574113-Aug-07 7:53 
GeneralRe: What makes a class IDisposable? Pin
iddqd51513-Aug-07 8:09
iddqd51513-Aug-07 8:09 
GeneralRe: What makes a class IDisposable? Pin
Mark Salsbery13-Aug-07 8:44
Mark Salsbery13-Aug-07 8:44 
GeneralRe: What makes a class IDisposable? Pin
iddqd51513-Aug-07 8:55
iddqd51513-Aug-07 8:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.