Component Object

rbulph

Junior Contributor
Joined
Feb 17, 2003
Messages
397
What's the need for the Component class? It only has a handful of properties and methods. Why couldn't you just have the Control class? Can you give me an example of the use of a Component which is not a Control?
 
I could be wrong, but I'd guess its for things like the Timer class. I believe this is a component, but it has no actually physical representation in a project like controls do.
 
Cags said:
I could be wrong, but I'd guess its for things like the Timer class. I believe this is a component, but it has no actually physical representation in a project like controls do.

Yes, you're right. It inherits from Component, not Control. Common dialogs are the same. I guess if you objects that have events and you want to make it easy to add them to a form, it's good to put those objects in the toolbox. Otherwise the user has to declare them With Events. So I suppose it's easier to have both those objects and controls inherit from a common base class for the purpose of programming the toolbox.
 
Compared to a control, a component is very simple. The biggest difference is that a component does not go on the form physically. It is shown in the component tray in the designer but at run-time it is simply held in a variable. Not having its own window and all of the variables and message processing that are necessary for a control is a resource-saver. More importantly, making a class a component instead of a control makes your intent for the use of the class more obvious.

The whole idea behind the component class is that it can be used in a designer, allowing us to do more in the designer and less code writing. It has nothing to do with controls.
 
Back
Top