On Mon, 5 Mar 2001, Aldo Calpini wrote:

> this is completely unclear to me.

Sorry, I was unclear.  A tag is a scalar value associated with the control
which is for application use.  It can be fetched and set but has no effect
on control behavior.

Why is this useful?  Say you have radio buttons for day of the week.  The
datum you need is 0-6 for Sunday-Saturday.  Right now you need seven
_Click subs which each set a different value or which call on a sub that
does the checking.

With tags you could put the correct data value in the tag when creating
the buttons and give them all the same name.  Then

sub DayOfWeekRadioButton_Click {
        my ( $source_radiobutton ) = @_;

        our $day_of_week_value = $source_radiobutton->Tag;
}

would work for all of them.

If I was doing Model/View/Controller with Win32-GUI then I would use the
tag value to hold a reference to the model object for that control:

sub SomeText_Change {
        my ( $control ) = @_;

        # Get the object representing what this textbox shows
        my $model_value_holder = $control->Tag;

        # Inform the abstract model that the value has changed
        $model_value_holder->set_value( $control->Text );
}


The motive for doing this is to get as much code out of the GUI elements
as possible.  This helps testing the logic seperately from the GUI and
helps to limit where errors can occur.  So usually I would have all my
text boxes, all my buttons, etc execute the same routines for dealing with
their model object.

Normally I would do this by subclassing the text control to do
model-specific handling and then using instances of the subclassed
control.  Since the perl objects in Win32-GUI are just handles I don't
know if that would make sense here.


   - Eric B.

--
"Pasteurized From Concentrate"


Reply via email to