Re: Problem Assigning members to XRC objects

Maarten Bent <[email protected]> Wed, 10 Sep 2025 19:57:58 +0200
Newsgroups gmane.comp.lib.wxwindows.general
Message-ID <[email protected]>
Hi Tim,

Is your example code trying to reference the same object?
Because in the Create function you use the XRC name "AttributeValue", 
but in the event handler you use XRC name "tcAttributeValue".

Secondly, you use "tcAttributeValue->Connect". I think this is 
incorrect. You want to Connect to the event handler of your class, not 
the event handler of tcAttributeValue.
It should be something like:
Connect(tcAttributeValue->GetId(), wxEVT_TEXT, 
wxTextEventHandler(EBrailleRequiredMetaPage::OnTextChange));

Even better would be to not use the legacy Connect, but instead use 
Bind. Which likely will warn about this problem at compile-time instead 
of run-time.
Bind(wxEVT_TEXT, &EBrailleRequiredMetaPage::OnTextChange, this, 
tcAttributeValue->GetId());

Hope this helps,
Maarten

On 10 Sept 2025 16:26, Tim Burgess wrote:
>
> Hi,
>
> I’m successfully loading an XRC file that contains subclass entries. 
> The relevant classes contain member variables for elements within the 
> XRC file, such as:
>
> classSampleNotebookPage: publicwxPanel
>
> {
>
> wxDECLARE_DYNAMIC_CLASS(SampleNotebookPage);
>
> public:
>
> SampleNotebookPage();
>
> // Creation
>
> boolCreate()
>
> {
>
> tcAttributeValue = XRCCTRL(*this, "AttributeValue", wxTextCtrl);
>
> tcAttributeValue->Connect(wxEVT_TEXT, 
> wxTextEventHandler(EBrailleRequiredMetaPage::OnTextChange));
>
> …
>
> };
>
> ~SampleNotebookPage();
>
> …
>
> wxTextCtrl * tcAttributeVallue;
>
> }
>
> I successfully initialize such members when I create an instance of 
> the class. However, though the handlers fire correctly, trying to 
> reference one of my member variables within the handler leads to 
> exceptions. Here’s an example:
>
> voidEBrailleRequiredMetaPage::OnTextChange(wxCommandEvent& event)
>
> {
>
> intid = event.GetId();
>
> if(id == XRCID("tcAttributeValue"))
>
> {
>
> tcAttributeValue= XRCCTRL(*this, "tcAttributeValue", wxTextCtrl);
>
> // Assertion here:
>
> if(tcAttributeValue->GetValue().Trim().IsEmpty())
>
> {
>
> …
>
> }
>
> else
>
> {
>
> …
>
> }
>
> }
>
> }
>
> If I try to access the member directly:
>
> tcTitle->GetValue();
>
> I get an exception.
>
> What am I missing here, as I thought I was following all of the 
> examples I’ve found.
>
> Many thanks in advance.
>
> Tim
>
> -- 
> Please read https://www.wxwidgets.org/support/mlhowto.htm before posting.
> ---
> You received this message because you are subscribed to the Google 
> Groups "wx-users" group.
> To unsubscribe from this group and stop receiving emails from it, send 
> an email to [email protected].
> To view this discussion visit 
> https://groups.google.com/d/msgid/wx-users/008f01dc225e%24eef3fd70%24ccdbf850%24%40raisedbar.net 
> <https://groups.google.com/d/msgid/wx-users/008f01dc225e%24eef3fd70%24ccdbf850%24%40raisedbar.net?utm_medium=email&utm_source=footer>.

-- 
Please read https://www.wxwidgets.org/support/mlhowto.htm before posting.
--- 
You received this message because you are subscribed to the Google Groups "wx-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion visit https://groups.google.com/d/msgid/wx-users/f5d6d539-b8bd-474e-a1c4-8ff4e7e666a5%40gmail.com.