Testing COM Interfaces at Run Time

VB5 provides interface inheritance through the use of the Implements keyword. For example, CFullTimeEmployee can implement the IEmployee interface. This interface might include basic information such as name, social security number, and date of birth. Another class, CPartTimeEmployee can also implement the IEmployee interface. You can then write code against the IEmployee interface without regard to the type of employee. To supply additional functionality, you might create an IEmp2 interface. To test whether an object is of a certain type, use the TypeOf keyword at run time. The format is “TypeOf object Is class/interface”. Here’s how to define two classes:

 Class CFullTimeEmployee:Implements IEmployeeImplements IEmp2Class CPartTimeEmployeeImplements IEmployeeDim objMyFTE as New CFullTimeEmployeeDim objMyPTE as New CPartTimeEmployee

Using TypeOf, you can query at run time which interfaces these objects support:

 Query	ReturnTypeOf objMyFTE Is CFullTimeEmployee	TrueTypeOf objMyFTE Is IEmployee	TrueTypeOf objMyFTE Is IEmp2	TrueTypeOf objMyFTE Is CPartTimeEmployee	FalseTypeOf objMyFTE Is Object	TrueTypeOf objMyFTE Is IUnknown	TrueTypeOf objMyPTE Is CPartTimeEmployee	TrueTypeOf objMyPTE Is IEmployee	TrueTypeOf objMyPTE Is IEmp2	FalseTypeOf objMyPTE Is Object	TrueTypeOf objMyPTE Is IUnknown	TrueTypeOf objMyPTE Is CFullTimeEmployee	False
Share the Post:
Share on facebook
Share on twitter
Share on linkedin


The Latest

microsoft careers

Top Careers at Microsoft

Microsoft has gained its position as one of the top companies in the world, and Microsoft careers are flourishing. This multinational company is efficiently developing popular software and computers with other consumer electronics. It is a dream come true for so many people to acquire a high paid, high-prestige job

your company's audio

4 Areas of Your Company Where Your Audio Really Matters

Your company probably relies on audio more than you realize. Whether you’re creating a spoken text message to a colleague or giving a speech, you want your audio to shine. Otherwise, you could cause avoidable friction points and potentially hurt your brand reputation. For example, let’s say you create a

chrome os developer mode

How to Turn on Chrome OS Developer Mode

Google’s Chrome OS is a popular operating system that is widely used on Chromebooks and other devices. While it is designed to be simple and user-friendly, there are times when users may want to access additional features and functionality. One way to do this is by turning on Chrome OS