https://wiki.freepascal.org/api.php?action=feedcontributions&user=Chrkl&feedformat=atomLazarus wiki - User contributions [en]2024-03-29T07:05:22ZUser contributionsMediaWiki 1.35.6https://wiki.freepascal.org/index.php?title=Talk:How_to_Write_a_Lazarus_Component&diff=81938Talk:How to Write a Lazarus Component2014-07-15T12:30:21Z<p>Chrkl: moved Talk:How To Write Lazarus Component to Talk:How to Write a Lazarus Component: more grammatical title</p>
<hr />
<div>To link an icon, it is also necessary to add LResources unit to the uses clause,<br />
and to add {$I TCustomControl1.lrs} to the body of the Register procedure.</div>Chrklhttps://wiki.freepascal.org/index.php?title=How_To_Write_Lazarus_Component&diff=81936How To Write Lazarus Component2014-07-15T12:30:20Z<p>Chrkl: moved How To Write Lazarus Component to How to Write a Lazarus Component: more grammatical title</p>
<hr />
<div>{{How_To_Write_Lazarus_Component}}<br />
<br />
This is a guide on how to build components. It was tested on Windows 7 running Lazarus 0.9.30.<br />
<br />
==Step 1: Create the package==<br />
<br />
* On the Lazarus IDE menu, click '''Package > New Package''' to run the Package Manager. <br />
<br />
[[Image:package_menu.png]]<br />
<br />
* A '''Save''' file dialog will appear. Chose a folder and a file name and press save. If the IDE prompts for using lowercase filenames press 'yes'.<br />
<br />
* Congratulations: You have just created your first package!<br />
<br />
[[Image:How_to_write_lazarus_component_package_maker.png|Package Maker]]<br />
<br />
==Step 2: Create the unit==<br />
You can create a new unit or use an existing file. Both options are described below.<br />
<br />
===Create a new unit===<br />
* Use the '''Add button > New component'''.<br />
<br />
[[Image:package_new_component.png]]<br />
<br />
* Choose a component like TComboBox.<br />
* Choose ''customcontrol1.pas'' as file name.<br />
* Click OK.<br />
<br />
<syntaxhighlight><br />
unit CustomControl1;<br />
<br />
{$mode objfpc}{$H+}<br />
<br />
interface<br />
<br />
uses<br />
Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, StdCtrls;<br />
<br />
type<br />
TCustomControl1 = class(TComboBox)<br />
private<br />
{ Private declarations }<br />
protected<br />
{ Protected declarations }<br />
public<br />
{ Public declarations }<br />
published<br />
{ Published declarations }<br />
end;<br />
<br />
procedure Register;<br />
<br />
implementation<br />
<br />
procedure Register;<br />
begin<br />
RegisterComponents('Standard',[TCustomControl1]);<br />
end;<br />
<br />
end.<br />
</syntaxhighlight><br />
<br />
* Install the package by clicking the 'install' button at the top of the package editor.<br />
<br />
[[Image:package_install.png]]<br />
<br />
* Now the IDE will ask you, if the IDE should be rebuilt. Say yes.<br />
<br />
[[Image:package_rebuild.png]]<br />
<br />
* Restart Lazarus and see your new component in the component palette. Congratulations: you have just installed your first package with your first package component. <br />
<br />
[[Image:package_installed.png]]<br />
<br />
{{Note| If you do not see your new component in the component palette, it is most likely that you are not running the re-compiled version of Lazarus. You can set where Lazarus builds to using Tools -> Options -> Files -> Lazarus directory. <br />
<br />
Instead of calling Lazarus directly, you also can use startlazarus, which starts the newly created Lazarus, for example the Lazarus executable in the ~/.lazarus directory, if you don't have write access to the directory Lazarus was installed into.}}<br />
<br />
===Add an existing unit===<br />
If you already had a unit you can add it to the package:<br />
<br />
[[Image:package_existing_unit.png]]<br />
<br />
* Click the '''Add''' button, go to the '''Add Files''' tab. At the Unit file name, browse to your existing file. Click '''Add files to package'''. If the package manager complains that the unit is not in the unit path, click yes to add the directory to the unit path.<br />
* Click the '''Add''' button again, go to the '''Add Files''' tab, browse to the ''.lrs'' file and click OK (See Step 3 about creating this icon file).<br />
* Click the '''Add''' button again, go to the '''New Requirement''' tab. In the Package name select '''LCL''' and click OK.<br />
<br />
The end result should look like this:<br />
<br />
[[Image:How_to_write_lazarus_component_package_maker_done.png|Package Maker]]<br />
<br />
* Click under the Files tree in the Package Manager. In the File Properties, make sure ''Register unit'' is checked.<br />
* Click the Options button. Select the IDE Integration tab. In Package Type, make sure Designtime and Runtime is selected.<br />
* Click the Compile button to check to see that the files compile without errors.<br />
* Click the Install button. Lazarus will rebuild and restart automatically.<br />
<br />
The component is created and ready to be used:<br />
<br />
[[Image:How_to_write_lazarus_component_created.png|Component Created]]<br />
<br />
==Step 3: Create icons for the package==<br />
You should create 24x24 pixel size PNG files as icons. <br />
<br />
FPC is capable of using standard resource files <tt>.rc</tt> or compiled resources <tt>.res</tt> since fpc version 2.6. See [[http://wiki.lazarus.freepascal.org/Lazarus_Resources#FPC_resources]]<br />
<br />
<br />
To do: write description of creating icons using FPC resources.<br />
<br />
The <tt>.lrs</tt>: see below.<br />
<br />
=== Using the Lazarus Image Editor===<br />
You can use [[Lazarus_Image_Editor| Lazarus Image Editor]] to create the icons in .lrs format.<br />
<br />
===Using lazres===<br />
<tt>lazres</tt> is usually located in the Lazarus tools directory.<br />
<br />
You may need to compile lazres at first use. <br />
Simply open the ''lazres.lpi'' in the IDE and click '''run > build''' in the menu.<br />
<br />
'''Create lrs file'''<br />
<br />
To create the lrs file run:<br />
<br />
<code>~/lazarus/tools/lazres samplepackage.lrs TMyCom.png</code><br />
<br />
Where <br />
* ''samplepackage'' is the name of your package<br />
* ''TMyCom'' is the name of your component.<br />
<br />
You can add more than one image to the lrs file by appending the image file name at the end. Eg. ~/lazarus/tools/lazres samplepackage.lrs TMyCom.png TMyOtherCom.png ...<br />
<br />
'''Sample'''<br />
<br />
Following is a sample of the resulting ''samplepackage.lrs'' file.<br />
<br />
<pre>LazarusResources.Add('TMyCom','PNG',[<br />
#137'PNG'#13#10#26#10#0#0#0#13'IHDR'#0#0#0#24#0#0#0#24#8#2#0#0#0'o'#21#170#175<br />
+#0#0#0#4'gAMA'#0#0#177#143#11#252'a'#5#0#0#0'|IDAT8O'#237#212#209#10#192' '#8<br />
+#5'P'#247#231#251's'#215#138#133#164#166'\'#220#195'`'#209'c'#157'L'#173#131<br />
+#153#169'd4'#168'dP'#137'r_'#235'5'#136'@Zmk'#16'd9'#144#176#232#164'1'#247<br />
+'I'#8#160'IL'#206'C'#179#144#12#199#140'.'#134#244#141'~'#168#247#209'S~;'#29<br />
+'V+'#196#201'^'#10#15#150'?'#255#18#227#206'NZ>42'#181#159#226#144#15'@'#201<br />
+#148#168'e'#224'7f<@4'#130'u_YD'#23#213#131#134'Q]'#158#188#135#0#0#0#0'IEND'<br />
+#174'B`'#130<br />
]);</pre><br />
<br />
Make sure to include your resource file in your new component source by adding the following at the bottom your component's unit and including "LResources" in the uses clause<br />
<br />
<syntaxhighlight><br />
initialization<br />
{$I samplepackage.lrs}<br />
</syntaxhighlight><br />
<br />
==Recompiling Packages==<br />
<br />
You need to rebuild the package every time you make changes to the ''mycom.pas'' file. To rebuild the package, open the ''samplepackage.lpk'' file in the Package Manager and click the Install button.<br />
<br />
==Removing Packages==<br />
<br />
* To remove installed components: on the IDE menu, click Package > Configure installed packages. The following image shows the Installed Packages tool.<br />
<br />
[[Image:How_to_write_lazarus_component_installed_components.png|Installed Components]]<br />
<br />
* Select the package you want to uninstall and click Uninstall selection.<br />
<br />
If something goes wrong with a package (e.g. package directory is deleted without first uninstalling it), Lazarus may not allow you to uninstall packages. To fix the problem, at the IDE menu click Tools > Build Lazarus. Lazarus will rebuild all packages and restart. You should now be able to uninstall problematic packages.<br />
<br />
==Enhancing mycom.pas==<br />
<br />
* The code in ''mycom.pas'' above gives you the basics on what you need to create a component. The following is an enhanced version with some tips on how to write procedures and events for components.<br />
* The ''OnChange2'' shows how to create events<br />
* The ''OnSample'' shows how to create custom events<br />
* ''MyText'' and ''MyText2'' shows different ways to write properties.<br />
* You can use TComboBox instead of TCustomComboBox as the base class, which publishes all properties as TComboBox. <br />
* If TCustomComboBox is used as the base class, you'll notice a lot of properties and events will be missing in the IDE Object Inspector. To add those properties and events, just copy and paste the properties as listed below ''// properties from TComboBox''. These list of properties can be got from the TComboBox declaration in the StdCtrls unit. Omit any property which you want to handle yourself.<br />
<br />
<syntaxhighlight><br />
unit mycom;<br />
<br />
{$mode objfpc}{$H+}<br />
<br />
interface<br />
<br />
uses<br />
Classes, SysUtils, StdCtrls, Forms, Dialogs,<br />
LCLType,LCLIntf,lresources,LCLProc;<br />
<br />
type<br />
<br />
TSampleEvent = procedure(MyText: String) of Object;<br />
<br />
TMyCom = class (TCustomComboBox)<br />
private<br />
FMyText: String;<br />
FOnChange2: TNotifyEvent;<br />
FOnSample: TSampleEvent;<br />
public<br />
constructor Create(TheOwner: TComponent); override;<br />
procedure CreateWnd; override;<br />
procedure Change; override;<br />
protected<br />
function GetMyText2: String;<br />
procedure SetMyText2(MyText: String);<br />
published<br />
property MyText: String read FMyText write FMyText;<br />
property MyText2: String read GetMyText2 write SetMyText2;<br />
property OnChange2: TNotifyEvent read FOnChange2 write FOnChange2;<br />
property OnSample: TSampleEvent read FOnSample write FOnSample;<br />
<br />
// properties from TComboBox<br />
property Align;<br />
property Anchors;<br />
property ArrowKeysTraverseList;<br />
property AutoComplete;<br />
property AutoCompleteText;<br />
property AutoDropDown;<br />
property AutoSelect;<br />
property AutoSize;<br />
property BidiMode;<br />
property BorderSpacing;<br />
property CharCase;<br />
property Color;<br />
property Ctl3D;<br />
property Constraints;<br />
property DragCursor;<br />
property DragMode;<br />
property DropDownCount;<br />
property Enabled;<br />
property Font;<br />
property ItemHeight;<br />
property ItemIndex;<br />
property Items;<br />
property ItemWidth;<br />
property MaxLength;<br />
property OnChange;<br />
property OnChangeBounds;<br />
property OnClick;<br />
property OnCloseUp;<br />
property OnContextPopup;<br />
property OnDblClick;<br />
property OnDragDrop;<br />
property OnDragOver;<br />
property OnDrawItem;<br />
property OnEndDrag;<br />
property OnDropDown;<br />
property OnEditingDone;<br />
property OnEnter;<br />
property OnExit;<br />
property OnGetItems;<br />
property OnKeyDown;<br />
property OnKeyPress;<br />
property OnKeyUp;<br />
property OnMeasureItem;<br />
property OnMouseDown;<br />
property OnMouseMove;<br />
property OnMouseUp;<br />
property OnStartDrag;<br />
property OnSelect;<br />
property OnUTF8KeyPress;<br />
property ParentBidiMode;<br />
property ParentColor;<br />
property ParentCtl3D;<br />
property ParentFont;<br />
property ParentShowHint;<br />
property PopupMenu;<br />
property ReadOnly;<br />
property ShowHint;<br />
property Sorted;<br />
property Style;<br />
property TabOrder;<br />
property TabStop;<br />
property Text;<br />
property Visible; <br />
end;<br />
<br />
procedure Register;<br />
<br />
implementation<br />
<br />
procedure Register;<br />
begin<br />
RegisterComponents('Sample',[TMyCom]);<br />
end;<br />
<br />
constructor TMyCom.Create(TheOwner: TComponent);<br />
begin<br />
inherited Create(TheOwner);<br />
Self.Style := csDropDownList;<br />
end;<br />
<br />
procedure TMyCom.CreateWnd;<br />
begin<br />
inherited CreateWnd;<br />
Items.Assign(Screen.Fonts);<br />
end;<br />
<br />
procedure TMyCom.Change;<br />
begin<br />
inherited;<br />
if Assigned(FOnChange2) then FOnChange2(Self);<br />
if Assigned(FOnSample) then FOnSample(FMyText);<br />
end;<br />
<br />
function TMyCom.GetMyText2: String;<br />
begin<br />
Result:=FMyText;<br />
end;<br />
<br />
procedure TMyCom.SetMyText2(MyText: String);<br />
begin<br />
FMyText:=MyText;<br />
end;<br />
<br />
initialization<br />
{$I samplepackage.lrs}<br />
<br />
end.<br />
</syntaxhighlight><br />
<br />
==Using embedded (visual) components==<br />
It's possible to use standard components embedded in your own components (look for example at TLabeledEdit or TButtonPanel).<br />
<br />
Let's say you want to create a custom panel with a TLabel on it. With the steps described above the base package and source files can be created.<br />
Now do the following to add a TLabel to the component:<br />
* Add a private attribute for the label component (FEmbeddedLabel: TLabel;).<br />
* Add a published read-only property for the label component (property EmbeddedLabel: TLabel read FEmbeddedLabel;)<br />
* Create the label in the component's (overridden) constructor (FEmbeddedLabel := TLabel.Create(self); )<br />
* Set the parent of the component (FEmbeddedLabel.Parent := self;)<br />
* If the component to be embedded is not a 'subcomponent' by default (like TBoundLabel, TPanelBitBtn etc) then add the call to SetSubComponent. This is necessary for the IDE so it knows that it has to store the properties of the embedded component as well. TLabel is not a subcomponent by default so the call to the method must be added (FEmbeddedLabel.SetSubComponent(true);).<br />
<br />
To sum it up you would get something like this (only the essential parts are shown):<br />
<br />
<syntaxhighlight><br />
TEnhancedPanel = class(TCustomControl)<br />
private<br />
{ The new attribute for the embedded label }<br />
FEmbeddedLabel: TLabel;<br />
<br />
public<br />
{ The constructor must be overriden so the label can be created }<br />
constructor Create(AOwner: TComponent); override;<br />
<br />
published<br />
{ Make the label visible in the IDE }<br />
property EmbeddedLabel: TLabel read FEmbeddedLabel;<br />
end;<br />
<br />
implementation<br />
<br />
constructor TEnhancedPanel.Create(AOwner: TComponent);<br />
begin<br />
inherited Create(AOwner);<br />
<br />
// Set default width and height<br />
with GetControlClassDefaultSize do<br />
SetInitialBounds(0, 0, CX, CY);<br />
<br />
// Add the embedded label<br />
FEmbeddedLabel := TLabel.Create(Self); // Add the embedded label<br />
FEmbeddedLabel.Parent := self; // Show the label in the panel<br />
FEmbeddedLabel.SetSubComponent(true); // Tell the IDE to store the modified properties<br />
FLabel.Name := 'EmbeddedLabel'; <br />
FLabel.Caption := 'Howdy World!';<br />
<br />
// Make sure the embedded label can not be selected/deleted within the IDE<br />
FLabel.ControlStyle := FLabel.ControlStyle - [csNoDesignSelectable];<br />
<br />
// Set other properties if necessary<br />
//...<br />
<br />
end;<br />
</syntaxhighlight><br />
<br />
==Using custom paint procedure==<br />
You can always subclass a component inside your program. For example, this implements a custom Paint procedure to a TLabel:<br />
<br />
<syntaxhighlight><br />
type<br />
TMyLabel = class(TLabel)<br />
public<br />
procedure Paint; override;<br />
end;<br />
{...}<br />
implementation<br />
{...}<br />
procedure TMyLabel.Paint;<br />
begin<br />
// your code to implement Paint, for example<br />
Canvas.TextOut(0,0,Caption);<br />
end; <br />
</syntaxhighlight><br />
<br />
Now you can create a MyLabel inside your program, at run time, with that overridden Paint procedure instead of the standard one.<br />
<br />
For most components, and for most methods, it would be recommendable to call inherited procedure inside it:<br />
<br />
<syntaxhighlight><br />
procedure TMyLabel.Paint;<br />
begin<br />
<br />
inherited Paint; /////////////////////<br />
<br />
// your code to implement Paint, for example<br />
Canvas.TextOut(0,0,Caption);<br />
end; <br />
</syntaxhighlight><br />
<br />
However, inherited behavior is not desirable in this case, since the second writing action would overlap the first (inherited) one.<br />
<br />
==Integrating the component with the IDE==<br />
<br />
===Property editors===<br />
<br />
Property editors provide custom dialogs to edit properties in the object inspector. For most properties, like strings, string lists, images, enumerated types and others, there are already default property editors, but if a custom component has a special kind of property it may require a custom dialog to edit the property.<br />
<br />
Each property editor is a class, which should descend from TPropertyEditor or one of its descendents and implement methods from this base class. They should be registered in the 'Register' procedure by using the function RegisterPropertyEditor from the unit PropEdits. It is a standard to name property editors with the property name followed by 'Property', for example TFieldProperty for the property editor of the TField property.<br />
<br />
<syntaxhighlight><br />
TPropertyEditor = class<br />
public<br />
function AllEqual: Boolean; Virtual;<br />
function AutoFill: Boolean; Virtual;<br />
procedure Edit; Virtual; // Activated by double-clicking the property value<br />
procedure ShowValue; Virtual; // Activated by control-clicking the property value<br />
function GetAttributes: TPropertyAttributes; Virtual;<br />
function GetEditLimit: Integer; Virtual;<br />
function GetName: ShortString; Virtual;<br />
procedure GetProperties(Proc: TGetPropEditProc); Virtual;<br />
function GetHint(HintType: TPropEditHint; x, y: integer): String; Virtual;<br />
function GetDefaultValue: AnsiString; Virtual;<br />
procedure GetValues(Proc: TGetStrProc); Virtual;<br />
procedure SetValue(const NewValue: AnsiString); Virtual;<br />
procedure UpdateSubProperties; Virtual;<br />
function SubPropertiesNeedsUpdate: Boolean; Virtual;<br />
function IsDefaultValue: Boolean; Virtual;<br />
function IsNotDefaultValue: Boolean; Virtual;<br />
// ... shortened<br />
end;<br />
</syntaxhighlight><br />
<br />
A good example for a property editor is the TFont property editor.<br />
<br />
One of the most common cases for property editors is properties which are classes. Because classes have many fields and can have a variety of formats, it's not possible for Lazarus to have the object inspector edit field able to edit it, like is done for strings and numeric types. <br />
<br />
For classes, a convention is to have the value field show permanently the name of the class in parentheses, for example "(TFont)" and the "..." button shows a dialog to edit this class. This behaviour, except for the dialog, is implemented by a standard property editor for classes called TClassPropertyEditor, which can be inherited from when writing property editors for classes: <br />
<br />
<syntaxhighlight><br />
TClassPropertyEditor = class(TPropertyEditor)<br />
public<br />
constructor Create(Hook: TPropertyEditorHook; APropCount: Integer); Override;<br />
function GetAttributes: TPropertyAttributes; Override;<br />
procedure GetProperties(Proc: TGetPropEditProc); Override;<br />
function GetValue: AnsiString; Override;<br />
property SubPropsTypeFilter: TTypeKinds Read FSubPropsTypeFilter<br />
Write SetSubPropsTypeFilter<br />
Default tkAny;<br />
end;<br />
</syntaxhighlight><br />
<br />
Going back to the TFont example, inheriting from TClassPropertyEditor already offers part of the desired behavior and then the TFontPropertyEditor class only needs to implement showing the dialog in the Edit method and set the attributes for the editor:<br />
<br />
<syntaxhighlight><br />
TFontPropertyEditor = class(TClassPropertyEditor)<br />
public<br />
procedure Edit; Override;<br />
function GetAttributes: TPropertyAttributes; Override;<br />
end;<br />
<br />
procedure TFontPropertyEditor.Edit;<br />
var <br />
FontDialog: TFontDialog;<br />
begin<br />
FontDialog := TFontDialog.Create(NIL);<br />
try<br />
FontDialog.Font := TFont(GetObjectValue(TFont));<br />
FontDialog.Options := FontDialog.Options + [fdShowHelp, fdForceFontExist];<br />
if FontDialog.Execute then SetPtrValue(FontDialog.Font);<br />
finally<br />
FontDialog.Free;<br />
end;<br />
end;<br />
<br />
function TFontPropertyEditor.GetAttributes: TPropertyAttributes;<br />
begin<br />
Result := [paMultiSelect, paSubProperties, paDialog, paReadOnly];<br />
end;<br />
</syntaxhighlight><br />
<br />
===Component editors===<br />
<br />
Component editors control the behavior of right-clicking and double clicking components in the form designer.<br />
<br />
Each component editor is a class, which should descend from TComponentEditor or one of its descendents and implement methods from this base class. They should be registered in the 'Register' procedure by using the function RegisterComponentEditor from the unit ComponentEditors. It is a standard to name component editors with the component name followed by 'Editor', for example TStringGridComponentEditor for the property editor of the TStringGrid component. Although user component editors should be based in TComponentEditor, most of its methods are actually from an ancestor, so it is necessary to also know TBaseComponentEditor:<br />
<br />
<syntaxhighlight><br />
TBaseComponentEditor = class<br />
protected<br />
public<br />
constructor Create(AComponent: TComponent;<br />
ADesigner: TComponentEditorDesigner); Virtual;<br />
procedure Edit; Virtual; Abstract;<br />
procedure ExecuteVerb(Index: Integer); Virtual; Abstract;<br />
function GetVerb(Index: Integer): String; Virtual; Abstract;<br />
function GetVerbCount: Integer; Virtual; Abstract;<br />
procedure PrepareItem(Index: Integer; const AnItem: TMenuItem); Virtual; Abstract;<br />
procedure Copy; Virtual; Abstract;<br />
function IsInInlined: Boolean; Virtual; Abstract;<br />
function GetComponent: TComponent; Virtual; Abstract;<br />
function GetDesigner: TComponentEditorDesigner; Virtual; Abstract;<br />
function GetHook(out Hook: TPropertyEditorHook): Boolean; Virtual; Abstract;<br />
procedure Modified; Virtual; Abstract;<br />
end;<br />
</syntaxhighlight><br />
<br />
The most important method of a component editor is Edit, which is called when the component is double clicked. When the context menu for the component is invoked the GetVerbCount and GetVerb methods are called to build the menu. If one of the verbs (which means menu items in this case) are selected, ExecuteVerb is called. There is a default component editor (TDefaultEditor) which implements Edit to search the properties of the component for the most appropriate one to be edited. It usually chooses an event, which is edited by adding it's skeleton code in the code editor and setting the cursor to be in place to add code for it.<br />
<br />
Other important methods from TBasComponentEditor are: ExecuteVerb(Index), which executes one of the extra menu items placed on the right-click popup menu; GetVerb – To return the name of each extra popup menu item. Note that t is the responsibility of the component editor to place special menu item caption characters like & to create a keyboard accelerator and “-” to create a separator; GetVerbCount – Returns the amount of items to be added to the popup menu. The index for the routines GetVerb and ExecuteVerb is zero based, going from 0 to GetVerbCount – 1; PrepareItem – Called for each verb after the menu item was created. Allows the menu item to be customized such as by adding subitems, adding a checkbox or even hiding it by setting Visible to false; Copy - Called when the component is being copied to the clipboard. The component data for use by Lazarus will always be added and cannot be modified. This method is instead for adding a different kind of clipboard information to paste the component in other applications, but which won't affect the Lazarus paste.<br />
<br />
A simple and interesting example is the TCheckListBox component editor which creates a dialog to edit. More convenient then implementing all methods from TBaseComponentEditor is inheriting from TComponentEditor, and this is what TCheckListBoxEditor does. This base class adds empty implementations for most methods and some default ones for others. For Edit it calls ExecuteVerb(0), so if the first item will be identical to the double-click action, which is a convention for editor, there is no need to implement Edit. This basic action for the double-click and first menu item is often a dialog, and for TCheckListBox this is also done:<br />
<br />
<syntaxhighlight><br />
TCheckListBoxComponentEditor = class(TComponentEditor)<br />
protected<br />
procedure DoShowEditor;<br />
public<br />
procedure ExecuteVerb(Index: Integer); override;<br />
function GetVerb(Index: Integer): String; override;<br />
function GetVerbCount: Integer; override;<br />
end;<br />
<br />
procedure TCheckGroupComponentEditor.DoShowEditor;<br />
var<br />
Dlg: TCheckGroupEditorDlg;<br />
begin<br />
Dlg := TCheckGroupEditorDlg.Create(NIL);<br />
try<br />
// .. shortened<br />
Dlg.ShowModal;<br />
// .. shortened<br />
finally<br />
Dlg.Free;<br />
end;<br />
end;<br />
<br />
procedure TCheckGroupComponentEditor.ExecuteVerb(Index: Integer);<br />
begin<br />
case Index of<br />
0: DoShowEditor;<br />
end;<br />
end;<br />
<br />
function TCheckGroupComponentEditor.GetVerb(Index: Integer): String;<br />
begin<br />
Result := 'CheckBox Editor...';<br />
end;<br />
<br />
function TCheckGroupComponentEditor.GetVerbCount: Integer;<br />
begin<br />
Result := 1;<br />
end;<br />
</syntaxhighlight><br />
<br />
==See also==<br />
* [[Extending the IDE]]<br />
* [[Lazarus Packages]] - A guide for creating a package under Lazarus<br />
* [[Components and Code examples]]<br />
* [[Lazarus Components]]<br />
* [[IDE Window: Add to Package]]<br />
<br />
You can post questions regarding this page [http://forum.lazarus.freepascal.org/index.php/topic,5789.0.html here]<br />
<br />
[[Category:Lazarus]]<br />
[[Category:Components]]<br />
[[Category:Packages]]<br />
[[Category:Code]]<br />
[[Category:Tutorials]]</div>Chrklhttps://wiki.freepascal.org/index.php?title=Talk:Lazarus_FAQ&diff=27572Talk:Lazarus FAQ2008-04-09T08:28:06Z<p>Chrkl: New section: /* Customizing component palette? */</p>
<hr />
<div>=== How do I donate money to lazarus? ===<br />
<br />
Does anyone know ?<br />
<br />
: Currently, the way to donate money for Lazarus is to pay someone to implement something missing on Lazarus (or to fix a bug). More information here: [[Bounties]] --[[User:Sekelsenmat|Sekelsenmat]] 13:35, 14 November 2006 (CET)<br />
<br />
=== Can I set the user interface to multiple document view instead of multiple top-level documents? ===<br />
<br />
Does anyone know? I would prefer a [http://en.wikipedia.org/wiki/Multiple_Document_Interface Multiple document interface] (or rather an [http://en.wikipedia.org/wiki/IDE-style_interface IDE-style interface]). // [[User:Liftarn|Liftarn]]<br />
<br />
It is not possible. At least not yet. It seems the problem is that some windows aren't dockable yet. // [[User:Liftarn|Liftarn]]<br />
<br />
On the mailing list Al Boldi said something about the "[[TStudio]] layout". "It doesn't use the docking subsystem, because that still needs some work, but it statically docks the complete IDE, with variable splitters, as a stop-gap solution. I even have a new version lined up, that supports docking non-modal dialogs like the Search Window, and the debug windows." // [[User:Liftarn|Liftarn]]<br />
<br />
=== Size part is false ===<br />
<br />
The graph (and surrounding text) of the binary size part is wrong. Lazarus apps do have a quick growth, but it doesn't remain linear, above 1.5-3MB, extra code is less likely to pull in new components, and the quick growth subsides. (see also size matters)<br />
<br />
A correct graph would grow with the same inclination as C++ above 3MB.<br />
<br />
Also, the heavier growth of C++ is a bit false. This only happens when STL is used in extreme forms.<br />
<br />
===Customizing component palette?===<br />
Hi.<br />
<br />
Is there a way to customize the Lazarus component palette in terms of tab-names, tab-order and merging tabs that only contain one or two components. I installed a larger number of additional packages that resulted in and endless palette that is really difficult to handle. Thanks in advance for any help on the matter. --[[User talk:Chrkl|chris]] 10:28, 9 April 2008 (CEST)</div>Chrkl