Adding an About dialog as a property to a custom component: what changed
Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.
Title: Adding an About dialog as a property to a custom component
| Old | New | Line | |
|---|---|---|---|
| 1 | + | ## Summary | |
| 2 | + | ||
| 3 | + | This article is for writers of Lazarus visual components (descended from TComponent or descendants) | |
| 4 | + | ||
| 5 | + | - 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 | |
| 6 | + | - 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. | |
| 7 | + | - As well as an 'OK' button, the dialog can also display a 'License' button | |
| 8 | + | - When clicked, this displays one of the standard licenses (GPL, LGPL etc) in a modal window | |
| 9 | + | ||
| 10 | + | This is what the application programmer would see when he drops your component onto a form: | |
| 11 | + | ||
| 12 | + | #### Object Inspector example screenshot | |
| 13 | + | ||
| 14 | + | <figure> | |
| 15 | + | <img src="Screenshot_MyCustomComponent_ObjectInspector.png" title="Screenshot_MyCustomComponent_ObjectInspector.png" /> | |
| 16 | + | <figcaption>Screenshot_MyCustomComponent_ObjectInspector.png</figcaption> | |
| 17 | + | </figure> | |
| 18 | + | ||
| 19 | + | #### About dialog example screenshot | |
| 20 | + | ||
| 21 | + | - Clicking the ellipse button shows this: | |
| 22 | + | ||
| 23 | + | <figure> | |
| 24 | + | <img src="Screenshot_MyCustomComponent_AboutBox.png" title="Screenshot_MyCustomComponent_AboutBox.png" /> | |
| 25 | + | <figcaption>Screenshot_MyCustomComponent_AboutBox.png</figcaption> | |
| 26 | + | </figure> | |
| 27 | + | ||
| 28 | + | #### License screen example screenshot | |
| 29 | + | ||
| 30 | + | - Clicking the License button shows this: | |
| 31 | + | ||
| 32 | + | <figure> | |
| 33 | + | <img src="Screenshot_MyCustomComponent_LGPL_LicenseScreen.png" title="Screenshot_MyCustomComponent_LGPL_LicenseScreen.png" /> | |
| 34 | + | <figcaption>Screenshot_MyCustomComponent_LGPL_LicenseScreen.png</figcaption> | |
| 35 | + | </figure> | |
| 36 | + | ||
| 37 | + | ## Download example code | |
| 38 | + | ||
| 39 | + | You 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/) | |
| 40 | + | ||
| 41 | + | ## Adding an About property to your new or existing component | |
| 42 | + | ||
| 43 | + | - Add the files aboutcomponentunit.pas and license.lrs to your component directory | |
| 44 | + | ||
| 45 | + | 1. Rename aboutcomponentunit.pas to about\<yourcomponentname\>unit.pas | |
| 46 | + | 2. In the pas file rename the Unit to match (1) | |
| 47 | + | 3. Open the renamed pas file and do Search/Replace to change all instances of "TAboutComponent" to TAbout\<yourcomponentname\> | |
| 48 | + | 4. In the line TAboutComponent = Class(TComponent), change the ancestor to your component's ancestor (if it's not TComponent) | |
| 49 | + | 5. Add the edited pas file to your component's package | |
| 50 | + | 6. In your component's class declaration, change it's ancestor to TAbout\<yourcomponentname\> (from step 3) | |
| 51 | + | 7. Compile, install and see the new clickable 'About' property in your component! | |
| 52 | + | ||
| 53 | + | ### Configuring the About property dialog | |
| 54 | + | ||
| 55 | + | - In your component's Constructor Create() set some, all or none of the following properties: | |
| 56 | + | - AboutBoxComponentName (string) | |
| 57 | + | - AboutBoxWidth (integer) | |
| 58 | + | - AboutBoxHeight (integer) | |
| 59 | + | - AboutBoxDescription (string - can contain LineEndings) | |
| 60 | + | - AboutBoxBackgroundColor (TColor, like clWhite) | |
| 61 | + | - AboutBoxFontName (string) | |
| 62 | + | - AboutBoxFontSize (integer) | |
| 63 | + | - AboutBoxVersion (string) | |
| 64 | + | - AboutBoxAuthorname (string) | |
| 65 | + | - AboutBoxOrganisation (string) | |
| 66 | + | - AboutBoxAuthorEmail (string) | |
| 67 | + | - AboutBoxLicenseType (string e.g. 'GPL', ModifiedGPL' etc) | |
| 68 | + | - You will have to recompile and reinstall your component to see the results. | |
| 69 | + | ||
| 70 | + | ## Example | |
| 71 | + | ||
| 72 | + | - Using the component [[ScrollText]] (available [here](http://www.charcodelvalle.com/scrollingtext/scrollingtext_component.zip)) | |
| 73 | + | - I have already renamed the AboutComponentunit to AboutScrolltextunit, and changed the class name from TAboutComponent to TAboutScrollText | |
| 74 | + | - TScrolltext is dereived from TGraphicControl so in the AboutScrollText unit I alter: | |
| 75 | + | ||
| 76 | + | `TAboutScrollText = class(TComponent) ` | |
| 77 | + | ||
| 78 | + | to | |
| 79 | + | ||
| 80 | + | `TAboutScrollText = class(TGraphicControl) ` | |
| 81 | + | ||
| 82 | + | - Then in my scrolltext unit, I change | |
| 83 | + | ||
| 84 | + | `TScrollingText = class(TGraphicControl) ` | |
| 85 | + | ||
| 86 | + | to | |
| 87 | + | ||
| 88 | + | `TScrollingText = class(TAboutScrollText) ` | |
| 89 | + | ||
| 90 | + | - Now the Scrolltext component has an 'About' property, but with default values. | |
| 91 | + | - So in my TScrollingText constructor, I now set my own values: | |
| 92 | + | ||
| 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 | + | ||
| 114 | + | - I then compile and install the scroller component to the IDE palette, and the 'About' property is part of the component. | |
| 115 | + | ||
| 116 | + | ## See Also | |
| 117 | + | ||
| 118 | + | - [[Lazarus Nongraphical Visual Component Example Code]] | |
| 119 | + | - [[ScrollText]] | |
| 120 | + | ||
| 121 | + | --- | |
| 122 | + | *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).* | |
| 123 | + | Category: Component Creation | |
| 124 | + | Category: Lazarus-CCR |
