From: Jeremy W. <jez...@ho...> - 2006-03-24 10:35:34
|
Hi, Brian Millham skin email on the users list has highlighted something that I've been thinking about for a while - how to make creating Win32-GUI classes easier/safer. One of the problems creating a Win32-GUI class is were to store the instance data for the object while allowing the events to have access to this data. In the current version of Win32-GUI you can stuff data into a structure and store it via the window with the UserData method, and then retrieve it in the event handler: my $win=create the window my $instancedata = create the instance data #attach the instance data to the window $win->UserData($instancedata); in the event handlers: #for window events my $instancedata=$self->UserData(); #for child events, such as buttons on the window my $instancedata=$self->GetParent->UserData(); This works well, but there is huge scope for clobbering the data if this approach was used for a formal class. Ok - in the class documentation you could mention that the instance data is stored as a hash, and if you need to store data via UserData you should use your own key - but I'm wondering if there is a better way to handle this? For example, we could add a "Data" method which could be used to store instance data, leaving the UserData method free for the user? Thoughts? Cheers, jez. |