Address Handler/AddressOf

Greetings,

I am trying to expand on the Blog where new control buttons are dynamically added with a .pressed event from a window button which actuates a container control to do: a) controls.Add(nControl),
b) Me.AddControl(nControl); where controls() is a property of the container. All is well, the example works. And I get-it sort of. What I don’t understand id AddressOf. Anyway…

Now I would like to further control the instantiated buttons with another mouse control event such as mouseWheel, or mouseDrag. However two roadblocks come up: 1) I don’t know how to pass on the event parameters; 2) When I press an instantiated button I can retrieve its .name (ControlPressedName.Text = tControl.name–> tControl As Desktop UIControl); but not the .index of the control—> ControlPressedIndex.Text = tControl.index.toString is always always 0 . I add the index when the button is being instantiated (nControl.Index=idxNumber…(however I would think this is unnecessary as Index is a predefined property of a control?)

If you have a suggestion(s) I would appreciate your help. I have done a lot looking already (days). BTW the documentation is much improved from a few months ago, TY

Carl

[Simplified: Adding User Interface Controls at Runtime – Xojo Programming Blog]

Thanks

When you use AddressOf in a statement like

AddHandler button.MouseWheel, AddressOf myMouseWheel

You’re telling the control that the code that handles the event is in a different location. The first property is always the control that sent the Event.

Something you may want to try…

In the code editor, type the name of an object that has Event Definitions on it, for instance DesktopButton. Right click in the middle of the name and you should see a menu item named Add Method which has a SubMenu called From Event, which in turn lists all of the item’s events. If you select the event you’re interested in, the IDE will create a correctly formatted method for use with AddHandler.

2 Likes