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.