Link to home
Start Free TrialLog in
Avatar of BJohn
BJohn

asked on

COMPonents

Why use components instead of units? What are the componets, do they do something?
ASKER CERTIFIED SOLUTION
Avatar of gysbert1
gysbert1

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gysbert1
gysbert1

Oh yes ...

I should have mentioned this.

Components are esentially only objects which could just as well have been included in units.  Actually a component is only a unit that is included in your delphi file. If you add a component to a form, have a look at it's uses clause. The new component's unit will be added to it. The unit also contains code that is exclusively for design time. The component's unit is precompiled by delphi (you should see this happen if you add any components). Delphi then creates object code that can be linked into your application and adds the design time code to complib.dcl which contains the behaviour of the component at design time.

A component is thus not only a unit, but an object that is situated inside a unit. This means that it does not only contain functions and variables like a unit, but you can have multiple instances of the same component in a single application that shares code segment but not the data segment.

To conclude, if you do not need the design-time interface and you  have your code as an object and you even implemented properties  by overloading the = operator, then using a component is no different from simply using a unit with your code in.
First of all: the points for this question are way to many!
The purpose of the components is to make the interface design
easier. The components allow you to set parameters and
connect their events to procedures easily for both visual
and non-visual types, and most of the visual components appear
in design time as they would in run time.
Of course you can combine regular units with components.

/// John

Seems like we have an echo here ;^)
Anytime you drag something onto a form (a label, an image box,
a edit box, a list box) those are components.  If you want to
add something new to your project, components are the way to
go.  Right now I'm designing a generic simulation system...
I've designed all the simulation devices as components...the
user simply drags a component onto their form, sets some
properties and away they go.  It's a little more complex than
this, but from a designer stand-point, components (properly
designed ones) can really simplify the visual design and all
the end-programming.

It's kind of hard to explain without actually demonstrating
the usefulness.