Thanks Glenn, using the GetFocus method to verify I was in the text
field at the beginning of the text field change event was exactly what I
needed. Also, just in case anyone else is interested, I had a stupd
logic error also. Basically
my $date1 = sprintf "%04d%02d%02d", ($win->End->GetDate())[2,1,0];
my $date2 = sprintf "%04d%02d%02d", ($win->Start->GetDate())[2,1,0];
$win->tfDays->Text( $date1 - $date2); }
Is broken like crazy. Subtracting 20040930 from 20041014 gives 84 days,
which is obviously not right. I changed to:
sub Start_Change
{
my $date1 = Date::Simple->new(sprintf "%04d-%02d-%02d",
($win->End->GetDate())[2,1,0]);
my $date2 = Date::Simple->new(sprintf "%04d-%02d-%02d",
($win->Start->GetDate())[2,1,0]);
my $range = Date::Range->new($date1, $date2);
$win->tfDays->Text( $range->length -1);
}
sub End_Change
{
my $date1 = Date::Simple->new(sprintf "%04d-%02d-%02d",
($win->End->GetDate())[2,1,0]);
my $date2 = Date::Simple->new(sprintf "%04d-%02d-%02d",
($win->Start->GetDate())[2,1,0]);
my $range = Date::Range->new($date1, $date2);
$win->tfDays->Text( $range->length -1);
}
sub tfDays_Change
{
return unless (Win32::GUI::GetFocus() ==
$win->tfDays->{-handle});
my $date = sprintf "%04d-%02d-%02d",
($win->End->GetDate())[2,1,0];
my $enddate = Date::Simple->new($date);
my $end = $enddate - $win->tfDays->Text();
$win->Start->SetDate(reverse(split("-", $end)));
}
which correctly calculates 14 days when given 2004-09-30 from 2004-10-14
by using the Date::Simple and Date::Range Modules. Doh!
Joe Frazier, Jr.
Senior Support Engineer
Peopleclick Service Support
Tel: +1-800-841-2365
E-Mail: [EMAIL PROTECTED]
> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On
> Behalf Of Glenn Linderman
> Sent: Thursday, October 14, 2004 3:18 AM
> To: Frazier, Joe Jr
> Cc: Win32GUI
> Subject: Re: [perl-win32-gui-users] Turn off an event handler?
>
> On approximately 10/11/2004 11:28 AM, came the following
> characters from the keyboard of Frazier, Joe Jr:
> > I have an app which has two radio buttons. One is a text
> field which
> > controls a date range ((today -1) - text field value to
> create a date.
> > The other is a set of two DateTime controls. The problem I
> am having
> > is that when one changes, I want the other to change in response:
> >
> > Here are the DateTime change event handlers:
> >
> > sub Start_Change
> > {
> > my $date1 = sprintf "%04d%02d%02d",
> ($win->End->GetDate())[2,1,0];
> > my $date2 = sprintf "%04d%02d%02d",
> ($win->Start->GetDate())[2,1,0];
> > $win->tfDays->Text( $date1 - $date2); }
> >
> > sub End_Change
> > {
> > my $date1 = sprintf "%04d%02d%02d",
> ($win->End->GetDate())[2,1,0];
> > my $date2 = sprintf "%04d%02d%02d",
> ($win->Start->GetDate())[2,1,0];
> > $win->tfDays->Text( $date1 - $date2); }
> >
> > and here is the Text field event handler:
> >
> > sub tfDays_Change
> > {
> > my $date = sprintf "%04d-%02d-%02d",
> ($win->End->GetDate())[2,1,0];
> > my $start = Date::Simple->new($date); my $end = $start -
> > $win->tfDays->Text(); $win->Start->SetDate(reverse(split("-",
> > $end))); }
> >
> > Now, here is my problem: When I change the days in the
> text box, I do
> > not have a problem, but when I change the date using the DateTime
> > (even just scrolling between months), the days in the text field
> > change, which causes the datetime to change, which causes
> the text field to change....
> >
> > I think everyone can understand the rest. What I am
> looking for is a
> > way to have the $win->tfDays->Text( $date1 - $date2) to
> NOT call the
> > tfDays_Change event. I assume there is a way to temporarily detach
> > the event handler from the object and then reattach using
> Hook/Unhook,
> > but I cannot find any examples. Can anyone help with an example in
> > using the Hook/Unhook methods?
>
> Well, you shouldn't use Hook/Unhook unless there is no other
> way to achieve your goals.
>
> I think what you are driving for is that you want the changes
> to propagate from the control that the user is changing, to
> the other controls, rather than just have all the possible
> propagations happens.
>
> On the other hand, if the calculations are consistent, there
> shouldn't be a negative effect from having the extra events
> trigger their code.
>
> But if there must be an inconsistency in the calculation,
> perhaps you could use the GetFocus() method to determine
> which control has the focus, and then only react to Change
> events for the if the control for which the Change event is
> called has the focus?
>
> >
> > Thanks,
> >
> >
> > Joe Frazier, Jr.
> >
>
> --
> Glenn -- http://nevcal.com/
> ===========================
> The best part about procrastination is that you are never
> bored, because you have all kinds of things that you should be doing.
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: IT Product Guide on
> ITManagersJournal
> Use IT products in your business? Tell us what you think of
> them. Give us
> Your Opinions, Get Free ThinkGeek Gift Certificates! Click to
> find out more
> http://productguide.itmanagersjournal.com/guidepromo.tmpl
> _______________________________________________
> Perl-Win32-GUI-Users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/perl-win32-gui-users
>
>