2
*****************************************************************************
4
* This file is part of the Lazarus Component Library (LCL) *
6
* See the file COPYING.modifiedLGPL, included in this distribution, *
7
* for details about the copyright. *
9
* This program is distributed in the hope that it will be useful, *
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
13
*****************************************************************************
15
Author: Mattias Gaertner
18
Registers a new designer base class (like TForm or TDataModule) in the IDE.
20
unit CustomComponentClass;
27
Classes, SysUtils, LCLProc, LResources, Forms, FormEditingIntf;
33
TMyComponentClass = class(TComponent)
35
FDemoProperty: integer;
37
procedure GetChildren(Proc: TGetChildProc; Root: TComponent); override;
39
constructor Create(TheOwner: TComponent); override;
41
property DemoProperty: integer read FDemoProperty write FDemoProperty;
52
FormEditingHook.RegisterDesignerBaseClass(TMyComponentClass);
57
procedure TMyComponentClass.GetChildren(Proc: TGetChildProc; Root: TComponent);
58
// this method is called by TWriter to retrieve the child components to write
61
OwnedComponent: TComponent;
63
DebugLn(['TMyComponentClass.GetChildren ComponentCount=',ComponentCount]);
64
inherited GetChildren(Proc, Root);
65
if Root = Self then begin
66
for I := 0 to ComponentCount - 1 do
68
OwnedComponent := Components[I];
69
if not OwnedComponent.HasParent then Proc(OwnedComponent);
74
constructor TMyComponentClass.Create(TheOwner: TComponent);
75
// init the component with an IDE resource
77
DebugLn(['TMyComponentClass.Create ',DbgSName(TheOwner)]);
78
GlobalNameSpace.BeginWrite;
80
inherited Create(TheOwner);
81
if (ClassType <> TMyComponentClass) and not (csDesigning in ComponentState)
83
if not InitResourceComponent(Self, TDataModule) then begin
84
raise EResNotFound.Create('Resource missing for class '+ClassName);
88
GlobalNameSpace.EndWrite;