Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where should I begin when building a component?

I am looking to build my own component and have no idea where to begin. I have some Delphi books but they are old and outdated, and am looking for some recommendations on tutorials/books to help me do this. The component will be pretty simple, basically 2 labels and an image. I need hundreds of these in an array, so I thought a component would be the best route. The text will adjust based on width etc, and have some mouseover events. So basically, where do I begin?

I am using Delphi 2009, this will be a win32 app.

Thanks!

like image 659
Austin Avatar asked Nov 20 '09 20:11

Austin


People also ask

How do you design a component?

First, you need to have a clear idea about the component's aim, why we need it, what it is to do; talk with the product manager or the lead designer, and ask them this information. It seems obvious, but believe me, each component has different possibilities, so it's essential to know which to focus on.

What must happen before you can create a class component?

Create a Class ComponentThe component has to include the extends React.Component statement, this statement creates an inheritance to React.Component, and gives your component access to React.Component's functions. The component also requires a render() method, this method returns HTML.


3 Answers

You can order Ray Konopka's book Dev. Custom Delphi 3 Components - PDF for 25$. It's a specialized book on the subject and very good for a beginner too.

The main principles behind developing components is:

  1. Whether the component is visual or not (Does it need a Canvas to paint on)

  2. Does it need a window handle or not (visual or non-visual)

Once you answered those questions you can look at Delphi's source code for examples.

like image 172
Mihaela Avatar answered Oct 13 '22 16:10

Mihaela


As far as I know, Delphi Component Design, by Danny Thorpe, is still the best book on the subject. Component design hasn't changed significantly in the last 15 years, so whatever books you have probably aren't as outdated as you think. There are three things to keep in mind while reading older references:

  1. Names of certain units have changed. There's no DsgnIDE anymore, for example. It's DesignIDE instead.

  2. Design-time code is strictly separated from run-time code now. This means you can't use DesignIDE in your component's unit, or else you're barred from using run-time packages. Older Delphi versions didn't have this technical restriction (although it's always been a legal restriction), so old code examples you find might need to change a little bit.

  3. Strings are Unicode now, so as with all old code examples you find, there might be some invalid assumptions about character sizes that you'll need to recognize.

The biggest obstacle to writing components is that you're expected to use various protected members of the classes you descend from, but those frequently aren't documented, so you'll have to be much more willing to go read the VCL source code for examples of how various methods are used.

like image 43
Rob Kennedy Avatar answered Oct 13 '22 15:10

Rob Kennedy


The easiest way to do what you want is to create a new form. Drop the labels and image and arrange them the way you want; if it suits your need, put them on a panel so they can be moved around as a unit.

Select all the components you want included (and including the panel if you chose to use one), and then click the Component item on the IDE's main menu, and select the "Create Component Template". (It's only enabled if you have selected components on the current form.) A dialog will appear asking you for a name for the new component, and the Component Palette page on which you want it to appear.

like image 40
Ken White Avatar answered Oct 13 '22 17:10

Ken White