Just like you thought, using an anonymous subroutine in the form of
  sub { call_lookup_patient_id($self, @_) }
as the callback should do the trick.


Andri


On Thu, 2009-08-06 at 09:02 -0300, Steve Cookson wrote:
> Hi,
> 
> [Sorry for the cross-posting, I've only just found this group].
> 
> I'm having difficulty passing an object to an event handler in Perl.
> 
> I have two events which populate a screen with patient details
> Either by pressing search and returning a value:
> 
>      Wx::Event::EVT_BUTTON(
>       $self, 
>       $self->{Ctl_Patient_Search_Btn}->GetId, 
>           \&call_lookup_patient);
> 
> or by exiting a field:
> 
>     Wx::Event::EVT_KILL_FOCUS(
>       $self->{Ctl_Patient_Ref_0_Txt}, 
>           \&call_lookup_patient_id);
> 
> *     call_lookup_patient_id  and
> *     call_lookup_patient
> 
> are nearly identical.  Both of them look up a patient's details 
> and populate a form ($self).  The issue is that 
> 
> EVT_BUTTON passes $self to "call_lookup_patient" and so is 
> successful in building the form while
> 
> EVT_KILL_FOCUS only passes $self->{Ctl_Patient_Ref_0_Txt} 
> without the rest of the form and so it can't be populated.
> 
> My question is how to access $self when it is not passed?
> 
> Can I create an anonymous subroutine to pass a global variable like this
> ($gl_self is a global version of $self):
> 
> Wx::Event::EVT_KILL_FOCUS($self->{Ctl_Patient_Ref_0_Txt},
>                                                               \&{$gl_self
> = $self;
>                                                    call_lookup_patient_id;
>                                                    $gl_self = $self;}
> 
> Thanks for your help. 
> 
> Regards
> 
> Steve
> 
> 

Reply via email to