Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

COMPonents

Posted on 1997-05-06
5
Medium Priority
?
240 Views
Last Modified: 2010-04-06
Why use components instead of units? What are the componets, do they do something?
0
Comment
Question by:BJohn
  • 3
5 Comments
 
LVL 2

Accepted Solution

by:
gysbert1 earned 600 total points
ID: 1335962
Componets are firstly visual, which units are not.

Delphi is a visual programming language in a sense. You can thus make a component act differently at runtime and at design time in order to ease the use thereof.

Secondly components have properties that is not that easy to implement in your unit. Definately not as easy as using variables. Any modification to the variable known as a property will have a function call in stead of a simple assignment. It overloads the = operator. So MyProperty=5 will not simply assign, it will call the assign function for MyProperty.

Component help can also be embedded into the standard Delphi help files. This makes shipping and 3rd party use much easier ...

Let me know if you need more reasons !!


0
 
LVL 2

Expert Comment

by:gysbert1
ID: 1335963
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.
0
 
LVL 4

Expert Comment

by:erajoj
ID: 1335964
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

0
 
LVL 2

Expert Comment

by:gysbert1
ID: 1335965
Seems like we have an echo here ;^)
0
 
LVL 3

Expert Comment

by:mheacock
ID: 1335966
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.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Loops Section Overview

876 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question