| RTL referenceGlossary|Tips/Tricks|FREE App/VCL|Best'O'Net|Books|Link To |
| Creating Custom Delphi Components - Inside and Out | |||||||||||||||||||||||||||
| Page 2: New...Component | |||||||||||||||||||||||||||
Creating a Component Get the source code here: Line.zip (1Kb)
We'll start off at the deep end. We're going to create a simple component, called TLine. It will be a graphical control that will draw a line in one of four directions. It won't do anything fancy, but it will deal with properties, drawing and other useful stuff.
How Do We Start? There are lots of possible base classes. Here's a small selection: This is, of course, a small snippet of the possible cases you might
need. We're interested in a small visual control, so TGraphicControl is
the best base class for us. There's no need for TCustomControl because our
component won't need window focus. We can get started now. Go to File->New and select component.
You'll be presented with a dialogue box. Fill it out like this: ![]() The only two things you need to fill out are the "Ancestor type" and "Class name" boxes. The rest get filled out automatically. Once you've done that, click the OK button and you get transported to the code editor with a skeleton class written out. First we need to let the compiler know what we'll be using. Each unit (a file, usually containing a class) has a "uses" clause. This lists what other files will be needed to compile the unit. Without this the compiler would have a really hard job so it's up to us to make sure it's correct. Note: You usually don't notice the "uses" clause as it's filled out with a large number of units by default (such as classes, sysutils, etc.). These units include most of the functionality you require. However, sometimes you have to add your own units (which usually listed in the help files for the appropriate class/procedure/function/type). We'll be needing the type TColor, which represents a colour. If you look this up in the help file you'll see it's within the 'Graphics' unit. Let's add that now before we start. Go to the very top of the file and find the uses part. It will look like this:
You can see that each unit needed is simply separated by a comma. We'll add Graphics to the uses unit. Make this change:
Question, Suggestions... |
|||||||||||||||||||||||||||
All graphics (if any) in this feature created by Zarko Gajic.
| More Delphi |
|
· Learn another routine every day - RTL Quick Reference. · Download free source code applications and components. · Talk about Delphi Programming, real time. · Link to the Delphi Programming site from your Web pages. · Tutorials, articles, tech. tips by date: 2001|2000|1999|1998 or by TOPIC. |
|
· NEXT ARTICLE:
GDI Graphics In Delphi. From simple lines to direct API calls: the ultimate tutorial to GDI graphics in Delphi. This tutorial will introduce you to some of the techniques in the GDI Delphi drawing. Look for: drawing lines and shapes, drawing pictures, flicker-free drawings, off-screen bitmaps, GDI drawings the API way... |
| Stay informed with all new and interesting things about Delphi (for free). |
|
|
| Got some code to share? Got a question? Need some help? |


