lmi
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Determine whether window created yet [Was: [lmi] wx segfault iterati


From: Greg Chicares
Subject: Re: Determine whether window created yet [Was: [lmi] wx segfault iterating on GetChildren()]
Date: Thu, 16 Mar 2006 21:18:26 +0000
User-agent: Mozilla Thunderbird 1.0.2 (Windows/20050317)

On 2006-3-15 19:04 UTC, Vadim Zeitlin wrote:
> On Wed, 15 Mar 2006 17:23:41 +0000 Greg Chicares <address@hidden> wrote:
> 
> GC> On 2006-3-11 15:06 UTC, Vadim Zeitlin wrote:
> GC> > On Sat, 11 Mar 2006 14:36:07 +0000 Greg Chicares <address@hidden> wrote:
> GC> > 
> GC> > GC> It's somewhat distasteful to use IsShown() to determine whether
> GC> > GC> a window has been "fully created". After all, a notebook that was
> GC> > GC> once shown may be temporarily hidden. But is there any better way?
> GC> > 
> GC> >  No, not out of the box. But you can assume that the window is fully
> GC> > created as soon as you get almost any message for it so it's common to 
> set
> GC> > a m_isCreated flag in EVT_WINDOW_CREATE or even EVT_SIZE or EVT_IDLE
> GC> > handlers.
> GC> 
> GC> Okay. I want to add a variable to a wxDialog-derived class:
> GC> 
> GC>   /// is_fully_created_: True iff dialog construction has completed and
> GC>   /// destruction has not yet begun.
> 
>  This will work but, again, I think it's a bit sloppy to rely on such
> generic flag. Usually you shouldn't need it and if/when you do there are
> more often than not better things to test for. In particular in your case I
> still think that a dynamic Connect() would be a better solution.

I do listen and try to learn, especially when you say the same thing
twice. I believe the lesson here is that

  int foo()
  {
      if(!okay_to_call_foo()) return;
      ...

isn't as good as never calling foo when it's not okay; and an event
can't be called before it's connected, so a dynamic Connect() is
equivalent but more elegant.

> GC> When should I change its value back to false, so that I can use this
> GC> flag to prevent a dialog that's in the process of destruction from
> GC> trying to do something it shouldn't?
> GC>   - a wxWindow::Destroy() virtual override?
> GC>   - an EVT_CLOSE handler?
> GC>   - my class's destructor?
> 
>  Probably the last one but, again, it really depends on what do you
> want/need it for exactly and so I'm afraid there is no generic "best"
> solution.

Right now, I'm reworking the Controller in my MVC framework for dialog
(notebook) input. Long ago, I had started using IsShown() for this
general purpose in numerous places. Later, I made it a member variable.
Still later I changed its meaning in a way that seems unclear now, even
to me. I'm trying to scrape off layers of band-aids, one at a time, to
discover why each one seemed like a good idea at the time, and then fix
the underlying problems in a better way.

I've added the dynamic Connect() idea to a to-do list in the source so
that I won't forget about it. I'm deferring it for now because it's a
matter of elegance, and I'm giving priority to matters of correctness.
But don't think I'm ignoring your advice.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]