Freetutes.com

VB6 beginners tutorial - Learn VB6

Advanced VB6 tutorial - Learn Advanced VB6

Systems Analysis - System analysis and Design tutorial for Software Engineering


You are here: Visual Basic > Advanced VB6 tutorial > Chapter 13

Implementing Delegated Methods

If you wish to expose some of the methods of your control's constituent controls to the developer, then you will need to implement delegated methods. A delegated method is a custom control method that acts as a wrapper for the method of an underlying constituent control usually with a single line of code calling the constituent control's method.

A delegated method is the only way you can let the developer access a method of a constituent control since constituent controls are Private to the UserControl object and so are unavailable to the developer.

You may give the delegated method the same name as the constituent control method it implements, or you might give it a different name to show that it's a slightly different animal.

As an example of a delegated method, you might have a ListBox constituent control on your UserControl and wish to allow the developer to call the ListBox Clear method to clear out the items in the ListBox. You could provide a custom method, ListClear, to delegate the Clear method of the ListBox, as in Listing 13.11.

LISTING 13.11
DELEGATING THE CLEAR METHOD OF THE ListBox

Public Sub ListClear()
   lstMyList.Clear
End Sub


  

<< Previous | Contents | Next >>

Home | About Us | Privacy Policy | Contact Us

Copyright © Freetutes.com | All Rights Reserved