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

Managed C++/CLI

 
QuestionRe: real time matrix conversion Pin
George L. Jackson13-Aug-07 13:58
George L. Jackson13-Aug-07 13:58 
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 
Well, it did not work exactly as was written, but certainly led me to the working code, thank you very much!
However, the solution I finally got seems ugly to me:
<font color=green>// I added public here so compiler stops giving a warning: 
// 'OnUpdateText': signature of non-private member contains assembly private 
// type 'EventTest::UpdateText'.</font>
<code>public</code> delegate void UpdateText( String^ );

<font color=green>// Needed to add public here so I can use this class as a base class later.</font>
<code>public</code> ref class SomeClass
{
  public:
    event UpdateText^ OnUpdateText;
};

public ref class Form1 : Form
{
  public:
    Form1()
    {
      InitializeComponent();
      someClass_ = gcnew SomeClass();
      someClass_->OnUpdateText += gcnew UpdateText( UpdateTextHandler );
    }

  private:
    SomeClass^ someClass_;
    void UpdateTextHandler( String^ text )
    {
      textBox->Text = text;
    }

<font color=green>// This is just my button handler. It calls foo() located in MyCode.CPP, which calls
// MyClass_UpdateText(), which fires an OnUpdateText event.</font>
    System::Void button1_Click (System::Object^ sender, System::EventArgs^  e) {
                 void foo (String^ Text);
                 foo ("Text for textBox");
             }

};

Now here is MyCode.CPP:
#include "stdafx.h"
#include "Form1.h"

using namespace EventTest;

<font color=green>// I had to add MyClass based on SomeClass as otherwise the compiler gives the error:
// error C3767: 'EventTest::SomeClass::OnUpdateText::raise': candidate function(s) not accessible. I
// looked up the error at MSDN: "Compiler Error C3767" and they had the example to avoid it via an extra
// class MyClass.</font>

<code>public ref class MyClass: public SomeClass
{
public:
    void MyClass_UpdateText (String^ Text) {
        SomeClass^ EventKeeper = gcnew SomeClass;
        EventKeeper->OnUpdateText (Text);
    }
};</code>

void foo (String^ Text) {
    MyClass^ y = gcnew MyClass();
    y->MyClass_UpdateText (Text);
}


Question #1: does it really have to be that twisted-complicated or it is just me being a beginner? To update a property on a Form from outside the Form I need to create and delegate an event, that has to be a member of SomeClass. Then to fire this event we have to create a new MyClass based on SomeClass with the actual event handler code and create an instance of it. And only then we can raise this event. Wow! Did I get it right or there is an extra step here? OMG | :OMG:

Question #2: If SomeClass is declared in front of Form1 then I cannot use the form designer. It says: The class Form1 can be designed, but is not the first class in the file. Visual Studio requires that designers use the first class in the file. Move the class code so that it is the first class in the file and try loading the designer again. But I cannot move it anywhere else because it must go before Form1() constructor as it uses this class, right? Is this something I just have to live with or there is a better way?

Sorry for the lengthy description but as I am getting to the bottom of this issue (it's been 2 days) I'd like other people who search for the same answer can read this thread and see something that actually works. I really appreciate the time spent on helping me, hopefully this will help a few more people!

Thanks again
Eugene
GeneralRe: Access controls from other modules of a program [modified] Pin
mid=574113-Aug-07 16:12
mid=574113-Aug-07 16:12 
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 

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.