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