| RTL referenceGlossary|Tips/Tricks|FREE App/VCL|Best'O'Net|Books|Link To |
| Creating Custom Delphi Components - Inside and Out | ||||||||||||||||||
| Page 4: Adding propeties to components | ||||||||||||||||||
Adding Properties
There should be no great surprises in there as you've seen similar property declarations in the previous tutorial part. Now, believe it or not, we've very nearly finished the component!
A quick note about "published": any properties in this section will be available in the Object Inspector at design-time. This is, of course, what we want. If you don't want the properties published (if, for example, you only create the component at run-time) then you can place properties in the "public" section. Properties there will be available to outside code, just like published properties, but will not appear in the Object Inspector. If you see "run-time" properties in the help files, it means they're public.
The next part is pretty fundamental to TLine - its Paint procedure. We need to draw the component, so it's time to add in some code for that. Since our component has TGraphicControl as a base class it gains a Paint procedure. We just need to modify this to draw our code and we're almost there. Add in this code to the component's "Protected" section:
The override part is a fancy bit, and means our procedure will get called instead of the base class's Paint procedure. We can write the good stuff now, namely the drawing procedure. Add this code in after the implementation part:
The only thing you shouldn't understand is the "inherited" bit. Because the Paint procedure belongs to the base class and we're overriding it, we don't want to miss out on important bits the base class does. The base class here might need to do things like set up the canvas to draw on, get device contexts, allocate resources, or whatever. If we don't let the base class do its thing by calling it via "inherited" we might just find our code blows up. Best not to let that happen, eh?
And that, my friend, is enough for a working component. Save the file and go to the Component->Install Component menu, select your file and say OK when it asks if you want to rebuild your library. If all goes well it should tell you that TLine has been registered. You can find it on the Samples palette page and try messing around with it.
![]() Question, Suggestions... Next page > On Constructors > Page 1, 2, 3, 4, 5, 6, 7, 8, 9 |
||||||||||||||||||
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? |

