CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 15

Threaded View

  1. #11
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: Working multiple forms using Visual C++ 2008

    Except that I'd still use the Owner property for this (certainly not the only way of doing it, but it is proven to be reliable to me), the snippet looks uncritical. ... except when the function gets called in the context of a worker thread. The String object itself is immutable and as such perfectly thread-safe, but querying the form's caption is not: Although it doesn't modify the observable state of the form, it belongs to the GUI manipulation category: It internally results in a WM_GETTEXT message being sent to the underlying native window object.

    Therefore, when called in a worker thread context, the property getter must be Invoke()d, like this:

    Code:
    public:
      String ^GetParentText()
      {
        String ^x = safe_cast<String ^>(Owner->Invoke(gcnew Func<String ^>(Owner, &Form::Text::get())));
        return x;  // Only so the function actually makes sense ;) (though this is a bit off-topic here)
      }
    I didn't actually test the snippet, but not applying any cast to Owner is not a typo: Owner is of type Form ^, and we're using a property that Form1 inherits from that base class, so no cast is required. (This difference doesn't look spectacular in this example, but it may be big-time helpful if Form1.h isn't accessible from here.)

    Quote Originally Posted by RogerD View Post
    I was out of touch for a while and when I came back noticed the site had had a face lift but was dismayed to find the find broken! I thought it was because I am using a new PC in a new house/country but see from your comment that's not it. Should I be telling somebody about it and whom?
    There's a huge thread about the forum software update in the Feedback section, and the search issue is one of the major ones discussed there. Of course you may report there, but you probably wouldn't be telling anyone anything new (it may add some pressure, though). IIRC there also have been workaroundssuggested for the search issue, but I never was successful applying them (I may simply have done it wrong, though).
    Last edited by Eri523; October 10th, 2012 at 05:00 PM.
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured