Sign in Join
Wiki copytemporary

Adding an About dialog as a property to a custom component: what changed

Revision 2 to 3. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
11## Summary
22
33This article is for writers of Lazarus visual components (descended from TComponent or descendants)
44
55- With the addition of a few lines of code to your component, it can display an 'About' property with an ellipsis button in the IDE Object Inspector
66- When the application programmer using your component clicks the button in the Object Inspector, a customised modal 'About' dialog is displayed with your info on it.
77- As well as an 'OK' button, the dialog can also display a 'License' button
88 - When clicked, this displays one of the standard licenses (GPL, LGPL etc) in a modal window
99
1010This is what the application programmer would see when he drops your component onto a form:
1111
1212#### Object Inspector example screenshot
1313
1414![](/wiki-images/e/ed/Screenshot_MyCustomComponent_ObjectInspector.png)
1515
1616#### About dialog example screenshot
1717
1818- Clicking the ellipse button shows this:
1919
2020![](/wiki-images/1/18/Screenshot_MyCustomComponent_AboutBox.png)
2121
2222#### License screen example screenshot
2323
2424- Clicking the License button shows this:
2525
2626![](/wiki-images/c/c1/Screenshot_MyCustomComponent_LGPL_LicenseScreen.png)
2727
2828## Download example code
2929
3030You can download the full source as described in this article from the lazarus CCR [here](https://sourceforge.net/p/lazarus-ccr/svn/HEAD/tree/components/)
3131
3232## Adding an About property to your new or existing component
3333
3434- Add the files aboutcomponentunit.pas and license.lrs to your component directory
3535
36361. Rename aboutcomponentunit.pas to about\<yourcomponentname\>unit.pas
37372. In the pas file rename the Unit to match (1)
38383. Open the renamed pas file and do Search/Replace to change all instances of "TAboutComponent" to TAbout\<yourcomponentname\>
39394. In the line TAboutComponent = Class(TComponent), change the ancestor to your component's ancestor (if it's not TComponent)
40405. Add the edited pas file to your component's package
41416. In your component's class declaration, change it's ancestor to TAbout\<yourcomponentname\> (from step 3)
42427. Compile, install and see the new clickable 'About' property in your component!
4343
4444### Configuring the About property dialog
4545
4646- In your component's Constructor Create() set some, all or none of the following properties:
4747 - AboutBoxComponentName (string)
4848 - AboutBoxWidth (integer)
4949 - AboutBoxHeight (integer)
5050 - AboutBoxDescription (string - can contain LineEndings)
5151 - AboutBoxBackgroundColor (TColor, like clWhite)
5252 - AboutBoxFontName (string)
5353 - AboutBoxFontSize (integer)
5454 - AboutBoxVersion (string)
5555 - AboutBoxAuthorname (string)
5656 - AboutBoxOrganisation (string)
5757 - AboutBoxAuthorEmail (string)
5858 - AboutBoxLicenseType (string e.g. 'GPL', ModifiedGPL' etc)
5959- You will have to recompile and reinstall your component to see the results.
6060
6161## Example
6262
6363- Using the component [[ScrollText]] (available [here](http://www.charcodelvalle.com/scrollingtext/scrollingtext_component.zip))
6464 - I have already renamed the AboutComponentunit to AboutScrolltextunit, and changed the class name from TAboutComponent to TAboutScrollText
6565- TScrolltext is dereived from TGraphicControl so in the AboutScrollText unit I alter:
6666
67-`TAboutScrollText = class(TComponent) `
67+```
68+TAboutScrollText = class(TComponent)
69+```
6870
6971to
7072
71-`TAboutScrollText = class(TGraphicControl) `
73+```
74+TAboutScrollText = class(TGraphicControl)
75+```
7276
7377- Then in my scrolltext unit, I change
7478
75-`TScrollingText = class(TGraphicControl) `
79+```
80+TScrollingText = class(TGraphicControl)
81+```
7682
7783to
7884
79-`TScrollingText = class(TAboutScrollText) `
85+```
86+TScrollingText = class(TAboutScrollText)
87+```
8088
8189- Now the Scrolltext component has an 'About' property, but with default values.
8290- So in my TScrollingText constructor, I now set my own values:
8391
84-`constructor TScrollingText.Create(AOwner: TComponent);`\
85-`begin`\
86-` inherited Create(AOwner);  `\
87-`..other constructor code..`\
88-`   // About dialog`\
89-` AboutBoxComponentName:='ScrollingText component';`\
90-` AboutBoxWidth:=400;`\
91-` // AboutBoxHeight (integer)`\
92-` AboutBoxDescription:='Component that shows a scrolling window.' + LineEnding +`\
93-` 'Use Lines property to set text and Active=True' + LineEnding +`\
94-` 'to use the component';`\
95-` AboutBoxBackgroundColor:=clWindow;`\
96-` AboutBoxFontName:='Arial';`\
97-` AboutBoxFontSize:=10;`\
98-` AboutBoxVersion:=C_VERSION;`\
99-` AboutBoxAuthorname:='Gordon Bamber';`\
100-` AboutBoxOrganisation:='Public Domain';`\
101-` AboutBoxAuthorEmail:='minesadorada@charcodelvalle.com';`\
102-` AboutBoxLicenseType:='LGPL';`\
103-`end;`
92+``` pascal
93+constructor TScrollingText.Create(AOwner: TComponent);
94+begin
95+ inherited Create(AOwner);
96+..other constructor code..
97+ // About dialog
98+ AboutBoxComponentName:='ScrollingText component';
99+ AboutBoxWidth:=400;
100+ // AboutBoxHeight (integer)
101+ AboutBoxDescription:='Component that shows a scrolling window.' + LineEnding +
102+ 'Use Lines property to set text and Active=True' + LineEnding +
103+ 'to use the component';
104+ AboutBoxBackgroundColor:=clWindow;
105+ AboutBoxFontName:='Arial';
106+ AboutBoxFontSize:=10;
107+ AboutBoxVersion:=C_VERSION;
108+ AboutBoxAuthorname:='Gordon Bamber';
109+ AboutBoxOrganisation:='Public Domain';
110+ AboutBoxAuthorEmail:='minesadorada@charcodelvalle.com';
111+ AboutBoxLicenseType:='LGPL';
112+end;
113+```
104114
105115- I then compile and install the scroller component to the IDE palette, and the 'About' property is part of the component.
106116
107117## See Also
108118
109119- [[Lazarus Nongraphical Visual Component Example Code]]
110120- [[ScrollText]]
111121
112122---
113123*From the Free Pascal wiki, page "Adding an About dialog as a property to a custom component", as it stood on 2016-07-15 after a change by Arent, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*
114124Category: Component Creation
115125Category: Lazarus-CCR

Back to history