Issues with subclass creation lazarus / 31-LCL ---------------------------------------------------------------------- pusuni · 2014-01-03 20:29 Hi!! this is my first post in the forum and sorry, if this subforum is not the right place for this message. I'm trying to make a new  control (class) derivated from TEdit class. A easy and simplified code  version of this class (the code is for example only)  is: Code: [Select]unit NumberEdit; {$mode objfpc}{$H+} interface uses    Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs,    StdCtrls, ExtCtrls; type    tNumero = ( real, entero );    TNumberEdit = class(TEdit)    private       { Private declarations }       Fmode                                       : tNumero;       TextoPrevio                                 : string;       TeclaTMP                                    : char;       FFontFcsName, FuenteTMP                     : TFont;       FErrSnd, FErrClr,FFontFcs                   : BOOLEAN;       PrimeraVezColor, PrimeraVezFuente           : BOOLEAN;       FColorErr, ColorTMP                         : TColor;       FValorEntero                                : Int64;       FValorReal                                  : extended;       Timer1                                      : TTimer;       FErrClrTime                                 : cardinal;    protected       { Protected declarations }    public       { Public declarations }    published       { Published declarations }       property ColorErr      : TColor    read FColorErr    write FColorErr;       property Mode          : tNumero   read FMode        write FMode        default real;       property ErrClr        : BOOLEAN   read FErrClr      write FErrClr;       property ErrClrTime    : cardinal  read FErrClrTime  write FErrClrTime;       property ErrSnd        : BOOLEAN   read FErrSnd      write FErrSnd;       property FontFcs       : BOOLEAN   read FFontFcs     write FFontFcs;       property FontFcsFont   : TFont     read FFontFcsName write FFontFcsName;       property ValorEntero   : Int64     read FValorEntero write FValorEntero;       property ValorReal     : extended  read FValorReal   write FValorReal;   end; procedure Register; implementation procedure Register; begin    {$I numberedit_icon.lrs}    RegisterComponents('Standard',[TNumberEdit]); end; end.       That code compile OK and I can create a new package with this new class: TNumberEdit. Now I can create a new form with this new control, but, I get a problem. The FontFcsFont is the TFont type. When in the Object inspector I select this one property  for setting the initials values,  I get the message: "Cannot assign as Nil to a Tfont" I think, I should get a font dialogue for setting those values.  I was searching information about that problem in different places:  they comment that I should create a Property Editors for TFont, But is it necessary? The ColorErr is  another type created by me (TColor type).  If I select it in object inspector, then I get the correct dialogue for setting those properties without any extra code Why yes here, and there, no? What's wrong in  my code? Thank very much in advanced ---------------------------------------------------------------------- typo · 2014-01-03 20:44 Try to initialize the property on the constructor as the same font as the control itself. ---------------------------------------------------------------------- engkin · 2014-01-03 20:51 TFont is a class, while TColor is a simple range. You need to create the font when you create your edit, and destroy it when you destroy your edit. Don't forget to provide some FontChange procedure. I learned about that by checking TControl source code: Code: Text  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i constructor TControl.Create(TheOwner: TComponent);...    FFont := TFont.Create;  FFont.OnChange := @FontChanged;... ---------------------------------------------------------------------- howardpc · 2014-01-03 21:03 TEdit descendants already have a published Font property. What is the purpose in adding another one? ---------------------------------------------------------------------- pusuni · 2014-01-05 11:14 Hi! Quote from: howardpc on January 03, 2014, 10:03:54 pmTEdit descendants already have a published Font property. What is the purpose in adding another one? Yes, I know. The new version of "my" Tedit, it  changes/toggles the font (name, properties, color...) when TEdit has the focus: if you are inside , one Font. If you are outside, another different font. The initial version (here is the code): Code: [Select]unit NumberEdit; {$mode objfpc}{$H+} interface uses    Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs,    StdCtrls, ExtCtrls; type    TNumberEdit = class(TEdit)    private       { Private declarations }       FFontFcsName, FuenteTMP                     : string;    //       FFontFcs                                    : BOOLEAN;       PrimeraVezFuente                            : BOOLEAN;    protected       { Protected declarations }       procedure DoEnter;                          Override;       procedure DoExit ;                          Override;       procedure MouseEnter;                       Override;       procedure MouseLeave;                       Override;    public       { Public declarations }       Constructor Create(AOwner : TComponent) ;   Override;    published       { Published declarations }       property FontFcs       : BOOLEAN   read FFontFcs     write FFontFcs;       property FontFcsFont   : string     read FFontFcsName write FFontFcsName;  //   end; procedure Register; implementation procedure Register; begin    {$I numberedit_icon.lrs}    RegisterComponents('Standard',[TNumberEdit]); end; Constructor TNumberEdit.Create(AOwner : TComponent); begin    inherited Create (AOwner);    PrimeraVezFuente   := TRUE; end; procedure TNumberEdit.DoEnter; begin    (*Al entrar en la zona de edicion, cambia la letra I - ON*)    inherited;    if FFontFcs then       begin          if PrimeraVezFuente then             begin                FuenteTMP := Font.Name; //                PrimeraVezFuente := FALSE;             end;          Font.Name := FFontFcsName//;       end; end; procedure TNumberEdit.DoExit; begin    (*Al entrar en la zona de edicion, cambia la letra  I - OFF*)    inherited;    if FFontFcs then       begin          if PrimeraVezFuente then             begin                FuenteTMP := Font.Name;  //                PrimeraVezFuente := FALSE;             end;          Font.Name := FuenteTMP; //       end; end; procedure TNumberEdit.MouseEnter; begin  (*Al entrar en la zona de edicion, cambia la letra II - ON*)    inherited;    if FFontFcs then       begin          if PrimeraVezFuente then             begin                FuenteTMP := Font.Name;     //                PrimeraVezFuente := FALSE;             end;          Font.Name := FFontFcsName;       end; end; procedure TNumberEdit.MouseLeave; begin  (*Al entrar en la zona de edicion, cambia la letra  II - OFF*)    inherited;    if FFontFcs then       begin          if PrimeraVezFuente then             begin                FuenteTMP := Font.Name; //                PrimeraVezFuente := FALSE;             end;          Font.Name := FuenteTMP; //       end; end; end.                    ONLY change the font name in the new  TNUMBEREDIT class. You can compile the code -  making a new package  -  and set the values: FontFcs = TRUE  (TRUE = enable the effect) FontFcsFont = Terminal (for example) It works properly (you can see in the two pictures): http://www.casimages.es/i/140105120121552113.png.html  http://www.casimages.es/i/140105120229807945.png.html As I said earlier, I thought about making a more sophisticated control : I created new property, FontFcsFont (FFontFcsName ) of TFONT type for toggling  between two different fonts: FONT <-> FONTFCSFONT I've been rewriting the source code and different  testing -  sorry for the delay  - following   the advices of typo and engkin (TFont is a class, while TColor is a simple range.): thanks a lot!!, both ) Quote unit NumberEdit; {$mode objfpc}{$H+} interface uses    Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs,    StdCtrls, ExtCtrls; type    TNumberEdit = class(TEdit)    private       { Private declarations }       FFontFcsName, FuenteTMP                     : TFont;    //       FFontFcs                                    : BOOLEAN;       PrimeraVezFuente                            : BOOLEAN;    protected       { Protected declarations }       procedure DoEnter;                          Override;       procedure DoExit ;                          Override;       procedure MouseEnter;                       Override;       procedure MouseLeave;                       Override;       procedure FontChanged(Sender: TObject)      Override; //    public       { Public declarations }       Constructor Create(AOwner : TComponent) ;   Override;    published       { Published declarations }       property FontFcs       : BOOLEAN   read FFontFcs     write FFontFcs;       property FontFcsFont   : TFont     read FFontFcsName write FFontFcsName;  //   end; procedure Register; implementation procedure Register; begin    {$I numberedit_icon.lrs}    RegisterComponents('Standard',[TNumberEdit]); end; Constructor TNumberEdit.Create(AOwner : TComponent); begin    inherited Create (AOwner);    PrimeraVezFuente   := TRUE;    FFontFcsName       := TFont.Create;    //    FFontFcsName.OnChange := @FontChanged;   //    FuenteTMP := TFont.Create;                 // end; procedure TNumberEdit.FontChanged(Sender: TObject); begin   end; procedure TNumberEdit.DoEnter; begin    (*Al entrar en la zona de edicion, cambia la letra I - ON*)    inherited;    if FFontFcs then       begin          if PrimeraVezFuente then             begin                FuenteTMP := Font; //                PrimeraVezFuente := FALSE;             end;          Font := FFontFcsName//;       end; end; procedure TNumberEdit.DoExit; begin    (*Al entrar en la zona de edicion, cambia la letra  I - OFF*)    inherited;    if FFontFcs then       begin          if PrimeraVezFuente then             begin                FuenteTMP := Font;  //                PrimeraVezFuente := FALSE;             end;          Font := FuenteTMP; //       end; end; procedure TNumberEdit.MouseEnter; begin  (*Al entrar en la zona de edicion, cambia la letra II - ON*)    inherited;    if FFontFcs then       begin          if PrimeraVezFuente then             begin                FuenteTMP := Font;     //                PrimeraVezFuente := FALSE;             end;          Font := FFontFcsName;   //       end; end; procedure TNumberEdit.MouseLeave; begin  (*Al entrar en la zona de edicion, cambia la letra  II - OFF*)    inherited;    if FFontFcs then       begin          if PrimeraVezFuente then             begin                FuenteTMP := Font; //                PrimeraVezFuente := FALSE;             end;          Font := FuenteTMP; //       end; end; end.                            ( NOTE: //and bold letters  -> modified lines) Now  I get the TFont control panel when  I select  this new property  for setting the initials values in the Object inspector, but I I can not  set the FontFcsFont (FFontFcsName )  FONT value  and  I sometimes get Access Violation message I guess the code is very buggy ( I don't know  what I should put into procedure TNumberEdit.FontChanged(Sender: TObject); ) and the Destroy?? Any ideas? Thanks in advanced ---------------------------------------------------------------------- engkin · 2014-01-05 17:29 QuoteI don't know  what I should put into procedure TNumberEdit.FontChanged(Sender: TObject); ) and the Destroy?? Checking the source code in $(LazarusDir)\lcl\include\control.inc to see what TControl does: Code: Text  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i destructor TControl.Destroy;  ...  FreeThenNil(FFont);...  inherited Destroy;...end;     As for TFont.OnChange and FontChanged, you should not override the original FontChanged if you do not need to. But you can borrow it for your font as well. Maybe you can keep this: Code: [Select]  FFontFcsName.OnChange := @FontChanged; And remove these: Code: [Select]...       procedure FontChanged(Sender: TObject)      Override; // ... procedure TNumberEdit.FontChanged(Sender: TObject); begin   end; ---------------------------------------------------------------------- howardpc · 2014-01-05 20:42 Quote from: pusuni on January 05, 2014, 12:14:19 pmThe new version of "my" Tedit, it  changes/toggles the font (name, properties, color...) when TEdit has the focus: if you are inside , one Font. If you are outside, another different font. Ah, we have a better idea of what you want to achieve. You don't need two properties: FontFcs (boolean) and FontFcsFont (TFont). This introduces unneeded redundancy. Setting FontFcsFont to the values Font has effectively turns FontFcs off, and giving it different properties from Font effectively turns it on. Also, you don't want to override FontChanged, (or use OnFontChange) as Engkin pointed out, since you want the built-in behaviour for changes in Font, not anything new. You need to call FontChanged (or send a font change message), not change what it does for you. I realise you want your component to do other things than auto-change the font when focused, but this cut-down version concentrates just on the font-change behaviour you are after, and shows the minimum methods you need to implement. Code: [Select]unit EditFontChange; {$mode objfpc}{$H+} interface uses   Classes, StdCtrls, Graphics, LMessages; const   DefaultFocusFontSize=16; type   { TEditAutoFontChange }   TEditAutoFontChange = class(TCustomEdit)   private     FFocusFont: TFont;     FTempFont: TFont;     procedure SetFocusFont(AValue: TFont);   protected     procedure DoEnter; override;     procedure DoExit; override;   public     constructor Create(AOwner: TComponent); override;     destructor Destroy; override;     property AutoSelected;   published     // new property     property FocusFont: TFont read FFocusFont write SetFocusFont;     // existing properties     property Action;     property Align;     property Alignment;     property Anchors;     property AutoSize;     property AutoSelect;     property BidiMode;     property BorderSpacing;     property BorderStyle;     property CharCase;     property Color;     property Constraints;     property DragCursor;     property DragKind;     property DragMode;     property EchoMode;     property Enabled;     property Font;     property HideSelection;     property MaxLength;     property ParentBidiMode;     property OnChange;     property OnChangeBounds;     property OnClick;     property OnContextPopup;     property OnDblClick;     property OnDragDrop;     property OnDragOver;     property OnEditingDone;     property OnEndDrag;     property OnEnter;     property OnExit;     property OnKeyDown;     property OnKeyPress;     property OnKeyUp;     property OnMouseDown;     property OnMouseEnter;     property OnMouseLeave;     property OnMouseMove;     property OnMouseUp;     property OnResize;     property OnStartDrag;     property OnUTF8KeyPress;     property ParentColor;     property ParentFont;     property ParentShowHint;     property PasswordChar;     property PopupMenu;     property ReadOnly;     property ShowHint;     property TabStop;     property TabOrder;     property Text;     property Visible;   end; implementation { TEditAutoFontChange } procedure TEditAutoFontChange.SetFocusFont(AValue: TFont); begin   if FFocusFont=AValue then Exit;   FFocusFont.Assign(AValue);   Perform(CM_FONTCHANGED, 0, 0); end; procedure TEditAutoFontChange.DoEnter; begin   inherited DoEnter;   if Assigned(Font) and Assigned(FFocusFont) and Assigned(FTempFont) then   if (FFocusFont<>Font) then begin     FTempFont.Assign(Font);     Font.Assign(FFocusFont);     Perform(CM_FONTCHANGED, 0, 0);   end; end; procedure TEditAutoFontChange.DoExit; begin   if (FFocusFont<>Font) then begin     Font.Assign(FTempFont);     Perform(CM_FONTCHANGED, 0, 0);   end;   inherited DoExit; end; constructor TEditAutoFontChange.Create(AOwner: TComponent); begin   inherited Create(AOwner);   FFocusFont:=TFont.Create;   FFocusFont.Assign(Self.Font);   FFocusFont.Style:=[fsBold];   FFocusFont.Size:=DefaultFocusFontSize;   FTempFont:=TFont.Create; end; destructor TEditAutoFontChange.Destroy; begin   FFocusFont.Free;   FTempFont.Free;   inherited Destroy; end; end. ---------------------------------------------------------------------- pusuni · 2014-01-07 10:51 Thanks  very much (a both) howardpc,  Wow!! I have NOT words for your code. I'm studing (There are things  I understand, but other no!! )  I don't understand why  "FTempFont.Assign(Font);" is different "FTempFont := Font;" the first statement works properly, the second  no.  I imagine ".Assign" procedure should do something more, no only assignement). Thanks again ---------------------------------------------------------------------- pusuni · 2014-01-12 15:21 Hi, again! I finished the new class, but I would like who some properties set a default values. For example, the ColorErr property is equal to  clRed, and so I think, if in this code Code: [Select]unit NumberEdit; {$mode objfpc}{$H+} interface uses    Classes, SysUtils, LResources, Graphics, StdCtrls, ExtCtrls, LMessages; type    tNumero = ( real, entero );    TNumberEdit = class(TEdit)    private       { Private declarations }       Fmode                                    : tNumero;       TextoPrevio                              : string;       TeclaTMP                                 : char;       ActivadoEfecto                           : BOOLEAN;       FFocusFont                               : TFont;       FTempFont                                : TFont;       FFocusFontEnable                         : BOOLEAN;       FErrSnd                                  : BOOLEAN;       FColorErr                                : TColor;       ColorTMP                                 : TColor;       FValorEntero                             : Int64;       FValorReal                               : extended;       Timer1                                   : TTimer;       FColorErrorTime                          : cardinal;    protected    public    published       { Published declarations }       property Mode            : tNumero  read FMode            write FMode            default real;       property ColorErr        : TColor   read FColorErr        write FColorErr;       property ColorErrorTime  : cardinal read FColorErrorTime  write FColorErrorTime;       property ErrSnd          : BOOLEAN  read FErrSnd          write FErrSnd;       property ValorEntero     : Int64    read FValorEntero     write FValorEntero;       property ValorReal       : extended read FValorReal       write FValorReal;    end;    procedure Register; implementation procedure Register; begin    {$I numberedit_icon.lrs}    RegisterComponents('Standard',[TNumberEdit]); end; end.  made the following changes Code: [Select]unit NumberEdit; {$mode objfpc}{$H+} interface uses    Classes, SysUtils, LResources, Graphics, StdCtrls, ExtCtrls, LMessages; type    tNumero = ( real, entero );    TNumberEdit = class(TEdit)    private       { Private declarations }       Fmode                                    : tNumero;       TextoPrevio                              : string;       TeclaTMP                                 : char;       ActivadoEfecto                           : BOOLEAN;       FFocusFont                               : TFont;       FTempFont                                : TFont;       FFocusFontEnable                         : BOOLEAN;       FErrSnd                                  : BOOLEAN;       FColorErr                                : TColor;       ColorTMP                                 : TColor;       FValorEntero                             : Int64;       FValorReal                               : extended;       Timer1                                   : TTimer;       FColorErrorTime                          : cardinal;    protected    public    published       { Published declarations }       property Mode            : tNumero  read FMode            write FMode            default real;       property ColorErr        : TColor   read FColorErr        write FColorErr    default clRed;       property ColorErrorTime  : cardinal read FColorErrorTime  write FColorErrorTime  default 500;       property ErrSnd          : BOOLEAN  read FErrSnd          write FErrSnd          default TRUE;       property ValorEntero     : Int64    read FValorEntero     write FValorEntero;       property ValorReal       : extended read FValorReal       write FValorReal;    end;    procedure Register; implementation procedure Register; begin    {$I numberedit_icon.lrs}    RegisterComponents('Standard',[TNumberEdit]); end; end. it should works properly, but no. I've compiled  and in the object inspector, the properties take arbitrary values  (usually 0) what's wrong  in my code? Thanks in advanced ---------------------------------------------------------------------- taazz · 2014-01-12 15:46 the default property specifier is for internal use. It instructs the streaming mechanism to avoid saving the property if the value it has it is the default. To set default values to your properties then override the create constructor and set the fields value there eg Code: [Select]constructor TNumberEdit.Create(aOWner:TComponent); begin   inherited create(aOwner);   FColorErr := clRed;   ...... // the rest of the initialization code.   end; ---------------------------------------------------------------------- pusuni · 2014-01-12 19:46 Thanks a lot, taazz ---------------------------------------------------------------------- howardpc · 2014-01-12 19:58 Quote from: pusuni on January 07, 2014, 11:51:27 amI don't understand why  "FTempFont.Assign(Font);" is different "FTempFont := Font;" the first statement works properly, the second  no.  I imagine ".Assign" procedure should do something more, no only assignement). FTempFont and Font are reference variables (pointers, though the syntax hides that fact).Code: [Select]FTempFont := Font; merely points the FTempFont variable to reference what Font is pointing to. The two variables now reference the same (single) object in memory. What you need is two different instances, whose property values differ. So you need to create a new valid instance (FTempFont) of the same type as Font but distinct from it, and then copy all Font's property and field values into FTempFont. This is achieved by the Assign() method of FTempFont, which takes as its only parameter a reference to the object whose property values should be assigned (copied over) to FTempFont. WritingCode: [Select] FTempFont := Font; is not wrong in this context only because it does not produce the desired effect, it is wrong because it causes a memory leak. Whatever font instance FTempFont previously referenced is now orphaned, and inaccessible, because you have just lost the only reference you had to it by pointing FTempFont to reference a different instance. When your program closes that originally allocated memory will not be deallocated, since nothing in your program now knows about it, or knows where to find it. Although such memory is usually called 'lost' or 'leaked', a more telling analogy might be to call it constipated memory, because it represents garbage which has not been removed, though it should have been. ---------------------------------------------------------------------- pusuni · 2014-01-13 12:32 Hi howardpc. Thank you for your  explanation.  I know about pointers, but I  didn't know  that TFONT is a pointer. Thanks, again ---------------------------------------------------------------------- typo · 2014-01-13 15:58 TFont is not a pointer. What howardpc says is that it "may be" a pointer if you don't use Assign method. ---------------------------------------------------------------------- pusuni · 2014-01-16 11:33 Thanks for the clarification I've finished the new control (new Class) TNumberEdit: Thank everyone for your help!! Now I'm trying to do  a new class with TNumberEdit and Tlabel/TStaticText classes (I would like  to add a label who looks in the left side of TNumberEdit control). ---------------------------------------------------------------------- howardpc · 2014-01-16 15:27 The source for TLabeledEdit will show you how to proceed if you're not clear. ---------------------------------------------------------------------- pusuni · 2014-01-19 15:10 Thanks very much for the info ---------------------------------------------------------------------- pusuni · 2014-01-25 09:46 Hi, again  I have got a problem with  TLabeledNumberEdit TLabeledNumberEdit  is a  new  control (class) derivated from TLabeledEdit class.  TLabeledEdit  is a special class in the Lazarus LCL: is based on a TEdit control (parent) and inside has another control: TStaticText called EditLabel. I would like add new propertys inside TEdit (parent) and other propertys  inside EditLabel (child) If in the public section  I add Code: [Select]property ColorError      : TColor   read FColorError    write FColorError; This property appears "in the root" of the object inspector (parent propertys). That's right! I make the same, for adding another property for EditLabel child. This property would be inside EditLabel tag in the object inspector, and not in the root, with the parent properties. The following source code: Quoteproperty EditLabel.ColorErrorLabel      : TColor   read FColorErrorLabel      write FColorErrorLabel; doesn't works properly. I get a message error when It was compiling Is there any easy way to add this property to the child class  ( EditLabel ) in the object inspector? Thanks in advanced ---------------------------------------------------------------------- howardpc · 2014-01-25 10:16 You would need to share the complete code for your new component before others could comment sensibly on how to achieve what you are after. ---------------------------------------------------------------------- taazz · 2014-01-25 16:11 Just remove the bold (editLabel)part from the property declaration, it should compile after that. If you want to change the included components then you have to rewrite the full control from the start you need to write 3 controls in total 1 the label with the extra properties you need 2 the edit with the extra properties and 3 rewrite the labelededit do not inherit this one write it from scratch using the new component you just wrote. ---------------------------------------------------------------------- pusuni · 2014-01-26 13:40 This is a simplified version - "stupid version", but it works properly if you compile - of source code of new  TLabeledNumberEdit control,   derivated from TLabeledEdit Code: [Select]unit LabeledNumberEdit; {$mode objfpc}{$H+} interface uses   Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, ExtCtrls; type    tNumero = ( real, entero );    TLabeledNumberEdit = class(TLabeledEdit)    private       { Private declarations }       Fmode                                    : tNumero;       FColorError                              : TColor;       FColorErrorLabel                         : TColor;       FColorErrorTime                          : cardinal;       FColorErrorLabelTime                     : cardinal;    protected      { Protected declarations }    public      { Public declarations }       constructor Create(AOwner : TComponent) ;   override;       destructor  Destroy;                        override;    published      { Published declarations }       property Mode                : tNumero  read FMode              write FMode;       property ColorError          : TColor   read FColorError        write FColorError;       property ColorErrorTime      : cardinal read FColorErrorTime    write FColorErrorTime;       property ColorErrorLabel     : TColor   read FColorErrorLabel   write FColorErrorLabel;       property ColorErrorLabelTime : cardinal read FColorErrorLabelTime write FColorErrorLabelTime;    end; procedure Register; implementation procedure Register; begin   {$I labelednumberedit_icon.lrs}   RegisterComponents('Additional',[TLabeledNumberEdit]); end; constructor TLabeledNumberEdit.Create(AOwner : TComponent); begin    inherited Create (AOwner);    FMode                := real;    FColorError          := clRed;    FColorErrorLabel     := clRed;    FColorErrorLabelTime := 500;    FColorErrorTime      := 500; end; destructor TLabeledNumberEdit.Destroy; begin    inherited Destroy; end; end.  The ColorErrorLabel and ColorErrorLabelTime are properties for EditLabel child control and not properties for parent control. I think, that the right place for those properties would be inside EditLabel (child) properties in the object inspector,  and not in  the root (parent class). Quoteproperty EditLabel.ColorErrorLabel      : TColor   read FColorErrorLabel      write FColorErrorLabel;QuoteJust remove the bold (editLabel)part from the property declaration, it should compile after that. Well I thought, that If I add the bold code, the properties appear inside "EditLabel" (The easy way!!) but not!! QuoteIf you want to change the included components then you have to rewrite the full control from the start you need to write 3 controls in total 1 the label with the extra properties you need 2 the edit with the extra properties and 3 rewrite the labelededit do not inherit this one write it from scratch using the new component you just wrote. The  second attempt was how you said   (very long  way) : created three controls.  My code compile, but I lost  my child (and all their properties) !! Code: [Select]unit LabeledNumberEdit; {$mode objfpc}{$H+} interface uses   Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, ExtCtrls; type    tNumero = ( real, entero );    TBoundLabelMejorado = class(TBoundLabel)    private       { Private declarations }       FColorErrorLabel                         : TColor;       FColorErrorLabelTime                     : cardinal;    protected      { Protected declarations }    public      { Public declarations }      constructor Create(AOwner : TComponent) ;   override;    published      { Published declarations }       property ColorErrorLabel     : TColor   read FColorErrorLabel   write FColorErrorLabel;       property ColorErrorLabelTime : cardinal read FColorErrorLabelTime write FColorErrorLabelTime;    end;    TCustomLabeledEditMejorado = class(TCustomLabeledEdit)     private      FEditLabel: TBoundLabelMejorado;      FLabelPosition: TLabelPosition;      FLabelSpacing: Integer; //     procedure SetLabelPosition(const Value: TLabelPosition); //     procedure SetLabelSpacing(const Value: Integer);    protected    public      constructor Create(AOwner: TComponent); override;      property EditLabel: TBoundLabelMejorado read FEditLabel; //     property LabelPosition: TLabelPosition read FLabelPosition //                                          write SetLabelPosition default lpAbove; //     property LabelSpacing: Integer read FLabelSpacing write SetLabelSpacing                                                                     default 3;    end;    TLabeledEditMejorado = class(TCustomLabeledEditMejorado)    published       property Alignment;       property Anchors;       property AutoSelect;       property AutoSize;       property BidiMode;       property BorderSpacing;       property BorderStyle;       property CharCase;       property Color;       property Constraints;       property DragCursor;       property DragMode;       property EchoMode;       property EditLabel;       property Enabled;       property Font;       property LabelPosition;       property LabelSpacing;       property MaxLength;       property ParentBidiMode;       property ParentColor;       property ParentFont;       property ParentShowHint;       property PasswordChar;       property PopupMenu;       property ReadOnly;       property ShowHint;       property TabOrder;       property TabStop;       property Text;       property Visible;       property OnChange;       property OnClick;       property OnDblClick;       property OnDragDrop;       property OnDragOver;       property OnEditingDone;       property OnEndDrag;       property OnEnter;       property OnExit;       property OnKeyDown;       property OnKeyPress;       property OnKeyUp;       property OnMouseDown;       property OnMouseMove;       property OnMouseUp;       property OnStartDrag;       property OnUTF8KeyPress;    end;    TLabeledNumberEdit = class(TLabeledEditMejorado)    private       { Private declarations }       Fmode                                    : tNumero;       FColorError                              : TColor;       FColorErrorTime                          : cardinal;    protected      { Protected declarations }    public      { Public declarations }       constructor Create(AOwner : TComponent) ;   override;       destructor  Destroy;                        override;    published      { Published declarations }       property Mode                : tNumero  read FMode              write FMode;       property ColorError          : TColor   read FColorError        write FColorError;       property ColorErrorTime      : cardinal read FColorErrorTime    write FColorErrorTime;    end; procedure Register; implementation procedure Register; begin   {$I labelednumberedit_icon.lrs}   RegisterComponents('Additional',[TLabeledNumberEdit]); end; constructor TBoundLabelMejorado.Create(AOwner : TComponent); begin    inherited Create (AOwner);      Name := 'SubLabel';   SetSubComponent(True);   if Assigned(AOwner) then     Caption := AOwner.Name;    FColorErrorLabel     := clRed;    FColorErrorLabelTime := 500; end; constructor TCustomLabeledEditMejorado.Create(AOwner : TComponent); begin    inherited Create (AOwner);      FLabelPosition := lpAbove;   FLabelSpacing := 3;   CreateInternalLabel; end; constructor TLabeledNumberEdit.Create(AOwner : TComponent); begin    inherited Create (AOwner);    FMode                := real;    FColorError          := clRed;    FColorErrorTime := 500; end; destructor TLabeledNumberEdit.Destroy; begin    inherited Destroy; end; end.  I Modified TBoundLabel for adding new properties. New control name: TBoundLabelMejorado ( Mejorado = enhanced, in Spainsh). Next , I made TCustomLabeledEditMejorado from TCustomLabeledEdit changed only FEditLabel from TBoundLabel type to TBoundLabelMejorado type. And I finaly, TLabeledEditMejorado.  I don't know where I lost my child class TLabeledEditMejorado. Any suggestions? There is other way. I think, the easiest way is to edit the extctrl.pp file and  add on line 822 one private section with my new variables. Not the most elegant, but it works. I prefer the second attempt, but I don't know how I do Any ideas? Thanks in advanced ---------------------------------------------------------------------- pusuni · 2014-02-01 18:49 I've finished the new control but I have a question. I've duplicated TBoundLabel (adding  extra properties ) and  TCustomLabeledEdit controls (changing Code: [Select]FEditLabel                             : TBoundLabel;  to FEditLabel                               : TBoundLabelMejorado; ). This last control ,TCustomLabeledEdit, in the protected  section has the following statement: Code: [Select]class procedure WSRegisterClass; override; and more later: Quoteclass procedure TCustomLabeledEdit.WSRegisterClass; begin   inherited WSRegisterClass;   RegisterCustomLabeledEdit; end;  RegisterCustomEdit function is defined in the ws32wsfactory file: Code: [Select]function RegisterCustomLabeledEdit: Boolean; Quotefunction RegisterCustomLabeledEdit: Boolean; alias : 'WSRegisterCustomLabeledEdit'; begin   Result := False; end; I don't understand the meaning of this function. What does it do? Is "WSRegisterClass"  function necessary to duplicate  for working properly the new version of  TCustomLabeledEdit control? Regards ---------------------------------------------------------------------- Martin_fr · 2014-02-01 19:19 "WSRegister" Is only needed if you need new widgetset functionality (code that is specific to win, gtk2 or carbon, ...). And even then, in your own component, you would normally use IFDEF. In short, you should not need any WSRegister... ---------------------------------------------------------------------- pusuni · 2014-02-02 09:37 OK! Thanks a lot ---------------------------------------------------------------------- pusuni · 2014-02-05 11:47 Hi again!! I've got another problem. I'm  trying  to put together 3 TEdit controls inside a TGroupBox control (TGroupBox1 is the name of new class/control). This is the code and compiles OK!!: Code: [Select]unit GroupBox1; {$mode objfpc}{$H+} interface uses   Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, StdCtrls, Lmessages; type   TGroupBox1 = class(TGroupBox)   private     { Private declarations }     FLigado1                                 : TEdit;     FLigado2                                 : TEdit;     FLigado3                                 : TEdit;     procedure x3SetColor (FColor : TColor);     function  x3GetColor (): TColor;     procedure x3SetFont (FFont : TFont);     function  x3GetFont (): TFont;   protected     { Protected declarations }   public     { Public declarations }     constructor Create(AOwner : TComponent) ;   override;     destructor  Destroy;                        override;   published     { Published declarations }     property x3Color      : TColor   read x3GetColor write x3SetColor;     property x3Font       : TFont    read x3GetFont       write x3SetFont;   end; procedure Register; implementation procedure Register; begin   RegisterComponents('Standard',[TGroupBox1]); end; procedure TGroupBox1.x3SetColor (FColor : TColor); begin    Fligado1.Color := FColor;    Fligado2.Color := FColor;    Fligado3.Color := FColor; end; function TGroupBox1.x3GetColor : TColor; begin    x3GetColor := FLigado1.Color; end; procedure TGroupBox1.x3SetFont (FFont : TFont); begin    if FLigado1.Font = FFont then Exit;    FLigado1.Font.Assign (FFont);    FLigado2.Font.Assign (FFont);    FLigado3.Font.Assign (FFont);    Perform(CM_FONTCHANGED, 0, 0); end; function  TGroupBox1.x3GetFont (): TFont; begin    x3GetFont.Assign (Fligado1.Font); end; constructor TGroupBox1.Create(AOwner : TComponent); begin      (* Parametros iniciales de TGRoupBox*)    inherited Create (AOwner);    BidiMode := bdRightToLeft;    Height := 136;    Width := 176;    ClientHeight := 118;    ClientWidth := 172;    Constraints.MaxHeight:=136;    Constraints.MaxWidth:=176;    Constraints.MinHeight:=136;    Constraints.MinWidth:=176;    FLigado1:= TEdit.Create(Self);    FLigado1.Parent:= Self;    FLigado1.SetSubComponent(true);    FLigado1.Name:= 'X';    FLigado1.ControlStyle := FLigado1.ControlStyle - [csNoDesignSelectable];    FLigado1.Left := 40;    FLigado1.Height := 24;    FLigado1.Top := 5;    FLigado1.Width := 130;    FLigado2:= TEdit.Create(Self);    FLigado2.Parent:= Self; (* Parametros iniciales del SEGUNDO Subcontrol dentro de TGRoupBox*)    FLigado2.SetSubComponent(true);    FLigado2.Name:= 'Y';    FLigado2.ControlStyle := FLigado2.ControlStyle - [csNoDesignSelectable];    FLigado2.Left := 40;    FLigado2.Height := 24;    FLigado2.Top := 44;    FLigado2.Width := 130;    FLigado3:= TEdit.Create(Self);    FLigado3.Parent:= Self; (* Parametros iniciales del TERCER Subcontrol dentro de TGRoupBox*)    FLigado3.SetSubComponent(true);    FLigado3.Name:= 'Z';    FLigado3.ControlStyle := FLigado3.ControlStyle - [csNoDesignSelectable];    FLigado3.Left := 40;    FLigado3.Height := 24;    FLigado3.Top := 83;    FLigado3.Width := 130; end; destructor TGroupBox1.Destroy; begin    inherited Destroy; end; end.                    I've a created a new property  (x3Color) in the object inspector to change Color inside each TEdit  control simultaneously and it works properly, but if I do the same, for changing the font in each TEdit, I get "Acess violation" error. If I delete all the code about "fonts" (x3Font property and functions/procedure, the code is OK) What's wrong with the font source code? Best Regards!! ---------------------------------------------------------------------- engkin · 2014-02-05 12:34 This function does not return a value (did you read your compiler messages?). More over it calles itself and it assigns a value to a result that does not exist!  Code: [Select]function  TGroupBox1.x3GetFont (): TFont; begin    x3GetFont.Assign (Fligado1.Font); end; ---------------------------------------------------------------------- pusuni · 2014-02-05 13:18 Engkin, the  source code  compiles Ok, without any error Messages and no warnings (no compiler messages!!, only OK!! ). How I must change this function and particulary this statement  x3GetFont.Assign (Fligado1.Font); for X3GetFont (type TFont) is equal to Fligado1.Font (type TFont)? ---------------------------------------------------------------------- engkin · 2014-02-05 14:05 Quote from: pusuni on February 05, 2014, 02:18:16 pmEngkin, the  source code  compiles Ok, without any error Messages and no warnings (no compiler messages!!, only OK!! ). I got Quotegroupbox1.pas(67,13) Warning: Function result variable does not seem to initialized I assume you need to change it to: Result := Fligado1.Font; ---------------------------------------------------------------------- pusuni · 2014-02-05 15:09 engkin, it's very strange: I haven't got any error messages from the compiler and I do not remember changing any compiler options ( all is "by default") Anyway, your code is  right. I compile and it does what it is supposed to do Thanks a lot, engkin!! ---------------------------------------------------------------------- engkin · 2014-02-06 01:56 Glad it worked for you. Quote from: pusuni on February 05, 2014, 04:09:57 pmengkin, it's very strange: I haven't got any error messages from the compiler and I do not remember changing any compiler options ( all is "by default") On my side I can hide/show hints, warnings...etc using: Project Options (Shift + Ctrl + F11)   Compiler Options     Verbosity Maybe you want to check that. ---------------------------------------------------------------------- pusuni · 2014-02-06 12:38 QuoteMaybe you want to check that. Thanks again, engkin ---------------------------------------------------------------------- pusuni · 2014-02-09 10:11 Testing different LCL components for my new controls, I think that I found a bug in TGroupBox . This control has a "Caption" (for the text) and  "Font" for the type of  font in the text of Caption. Well, you can changes the color of the font and the control doesn't change the font color I've tested different controls, and only this one doesn't works properly. Is this a bug ? Where should  I notify the problem for fixing? It happen in 1.0.14 and 1.2RC2  version Regards ---------------------------------------------------------------------- howardpc · 2014-02-09 12:41 Quote from: pusuni on February 09, 2014, 11:11:36 amWhere should  I notify the problem for fixing? see http://wiki.lazarus.freepascal.org/How_do_I_create_a_bug_report ---------------------------------------------------------------------- pusuni · 2014-02-09 13:13 Thanks, howardpc Additional testing:  Linux version  works properly.  Only Windows versions are wrong ---------------------------------------------------------------------- pusuni · 2014-02-16 15:24 New Issue!!  I've put together three TLabeledEdit Controls plus a Tlabel, inside Tpanel control. I've called the new control, TPanelG3 That is the code: Code: [Select]unit PanelG3; {$mode objfpc}{$H+} interface uses   Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, ExtCtrls, StdCtrls; type   TPanelG3 = class(TPanel)   private     { Private declarations }     FControlX                                 : TLabeledEdit;     FControlY                                 : TLabeledEdit;     FControlZ                                 : TLabeledEdit;     FControlLabel                             : TLabel;   protected     { Protected declarations }   public     { Public declarations }     constructor Create(AOwner : TComponent) ;   override;     destructor  Destroy;                        override;   //      property ControlX: TLabeledNumberEdit read FControl1;   //      property ControlY: TLabeledNumberEdit read FControl2;   //     property ControlZ: TLabeledNumberEdit read FControl3;   published     { Published declarations }     property ControlX: TLabeledEdit read FControlX;     property ControlY: TLabeledEdit read FControlY;     property ControlZ: TLabeledEdit read FControlZ;     property ControlLabel: TLabel read FControlLabel;   end; procedure Register; implementation procedure Register; begin   RegisterComponents('Standard',[TPanelG3]); end; constructor TPanelG3.Create(AOwner : TComponent); begin      (* Parametros iniciales de Provisional*)    inherited Create (AOwner);    Height := 136;    Width := 176;    ClientHeight := 132;    ClientWidth := 172;    Constraints.MaxHeight:=136;    Constraints.MaxWidth :=176;    Constraints.MinHeight:=136;    Constraints.MinWidth :=176;    Align := alCustom;    BevelInner := bvLowered;    BevelOuter := bvLowered;    BorderStyle := bsSingle;    (* FControlX - Parametros iniciales del PRIMER Subcontrol dentro de TGRoupBox*)    FControlX:= TLabeledEdit.Create(Self);    FControlX.Parent:= Self;    FControlX.SetSubComponent(true);    FControlX.ControlStyle := FControlX.ControlStyle - [csNoDesignSelectable];    FControlX.Name := 'X';    FControlX.Left := 36;    FControlX.Height := 23;    FControlX.Top := 20;    FControlX.Width := 130;    (* FControlY - Parametros iniciales del SEGUNDO Subcontrol dentro de TGRoupBox*)    FControlY:= TLabeledEdit.Create(Self);    FControlY.Parent:= Self;    FControlY.SetSubComponent(true);    FControlY.ControlStyle := FControlY.ControlStyle - [csNoDesignSelectable];    FControlY.Name := 'Y';    FControlY.Left := 36;    FControlY.Height := 23;    FControlY.Top := 59;    FControlY.Width := 130;    (* FControlZ - Parametros iniciales del TERCER Subcontrol dentro de TGRoupBox*)    FControlZ:= TLabeledEdit.Create(Self);    FControlZ.Parent:= Self;    FControlZ.SetSubComponent(true);    FControlZ.ControlStyle := FControlZ.ControlStyle - [csNoDesignSelectable];    FControlZ.Name := 'Z';    FControlZ.Left := 36;    FControlZ.Height := 23;    FControlZ.Top := 98;    FControlZ.Width := 130;    (* FControlLabel - Parametros iniciales del CUARTO Subcontrol dentro de TGRoupBox*)    FControlLabel:= TLabel.Create(Self);    FControlLabel.Parent:= Self;    FControlLabel.SetSubComponent(true);    FControlLabel.ControlStyle := FControlLabel.ControlStyle - [csNoDesignSelectable];    FControlLabel.Name := 'Etiqueta';    FControlLabel.Left := 129;    FControlLabel.Height := 31;    FControlLabel.Top := -2;    FControlLabel.Width := 37;    FControlLabel.Align := alCustom;    FControlLabel.Alignment := taRightJustify;    FControlLabel.AutoSize := False;    FControlLabel.BidiMode := bdRightToLeftNoAlign;    FControlLabel.Caption := 'XYZ';    FControlLabel.ParentBidiMode := False;    FControlLabel.ParentColor := False; end; destructor TPanelG3.Destroy; begin    FControlLabel.Free;    FControlZ.Free;    FControlY.Free;    FControlX.Free;    inherited Destroy; end; end. I can compile the code without any problems. I can take one/two/..  of  these new controls, and I can put them in a new form, without any problems, but when I compile the new form, the IDE hangs up completely, without any error messages. What's wrong in my code? (If I change TLabeledEdit to TEdit, all works properly. Is  my code wrong, or is  the TLabeledEdit code, wrong? Regards ---------------------------------------------------------------------- howardpc · 2014-02-16 16:22 You're publishing three TLabeledEdits as properties, and the Object Inspector has no default property editor for a TLabeledEdit property. Probably you don't need to publish the entire class as a property (it will bulk up the RTTI of your composite component greatly to little purpose). Better to publish properties of simple types, and only those that are really needed. For this reason you would be better advised to base your internal private controls on TCustomXXX ancestors, and avoid a whole slew of published stuff you don't really need. Something along these lines: Code: [Select]  TPanelG3Ex = class(TCustomPanel)   private     FControlX           : TCustomLabeledEdit;     FControlY           : TCustomLabeledEdit;     FControlZ           : TCustomLabeledEdit;     FControlLabel       : TCustomLabel;     function GetLabelCaption: string;     function GetXText: string;     function GetYText: string;     function GetZText: string;     procedure SetLabelCaption(AValue: string);     procedure SetXText(AValue: string);     procedure SetYText(AValue: string);     procedure SetZText(AValue: string);   public     constructor Create(AOwner : TComponent) ;   override;     destructor  Destroy;                        override;   published     property XText: string read GetXText write SetXText;     property YText: string read GetYText write SetYText;     property ZText: string read GetZText write SetZText;     property LabelCaption: string read GetLabelCaption write SetLabelCaption;   end;              Your property setters and getters would then be something like this Code: [Select]... function TPanelG3Ex.GetXText: string; begin   Result:=FControlX.Text; end; procedure TPanelG3Ex.SetXText(AValue: string); begin   if not SameText(AValue, FControlX.Text) then     FControlX.Text:=AValue; end; ---------------------------------------------------------------------- pusuni · 2014-02-17 13:57 Hi!! HowardPC The first version of the control that I made, had very little properties. If you look at the source code in previous post, you can see in the Published  section some lines with //, where  previously I defined the new controls (TLabeledEdtit), inside the  TPanel control, without any compiled problems. At the begining, I  only  declared those  properties that I really needed,  but still, I have a lot: That is the code, for some of them: Code: [Select]      function  x1GetValueIntegerX ()          : int64;       function  x1GetValueIntegerY ()          : int64;       function  x1GetValueIntegerZ ()          : int64;       function  x1GetValueRealX    ()          : extended;       function  x1GetValueRealY    ()          : extended;       function  x1GetValueRealZ    ()          : extended;       procedure x1SetEditLabelCaptionX (FLabel : string);       function  x1GetEditLabelCaptionX ()      : string;       procedure x1SetEditLabelCaptionY (FLabel : string);       function  x1GetEditLabelCaptionY ()      : string;       procedure x1SetEditLabelCaptionZ (FLabel : string);       function  x1GetEditLabelCaptionZ ()      : string;       procedure x3SetParentColor (FParentColor : BOOLEAN);       function  x3GetParentColor   ()          : BOOLEAN;       procedure x3SetParentFont (FParentFont : BOOLEAN);       function  x3GetParentFont    ()          : BOOLEAN;       procedure x3SetParentBidiMode (FParentBidiMode: BOOLEAN);       function  x3GetParentBidiMode()          : BOOLEAN;       procedure x3SetBidiMode (FBidiMode: TBiDiMode);       function  x3GetBidiMode      ()          : TBiDiMode;       procedure x3SetLabelPosition (FLabelPosition: TLabelPosition);       function  x3GetLabelPosition ()          : TLabelPosition;       procedure x3SetMaxLength (FMaxLength: integer);       function  x3GetMaxLength     ()          : integer;       procedure x3SetMode (FMode : tNumero);       function  x3GetMode          ()          : tNumero;       procedure x3SetColor (FColor : TColor);       function  x3GetColor         ()          : TColor;       procedure x3SetColorError (FColor: TColor);       function  x3GetColorError    ()          : TColor;       procedure x3SetColorErrorTime (FColorTime : cardinal);       function  x3GetColorErrorTime()          : cardinal;       procedure x3SetSoundError (FSoundError : BOOLEAN);       function  x3GetSoundError ()             : BOOLEAN;       procedure x3SetFont (AValue: TFont);       function  x3GetFont       ()             : TFont;       procedure x3SetFocusFont (AValue: TFont);       function  x3GetFocusFont  ()             : TFont;       procedure x3SetEditLabelBidiMode (FBidiMode: TBiDiMode);       function  x3GetEditLabelBidiMode ()      : TBiDiMode;       procedure x3SetEditLabelColor (FColor : TColor);       function  x3GetEditLabelColor ()         : TColor;       procedure x3SetEditLabelColorError (FColor: TColor);       function  x3GetEditLabelColorError ()    : TColor;       procedure x3SetEditLabelColorErrorTime (FColorTime : cardinal);       function  x3GetEditLabelColorErrorTime (): cardinal;       procedure x3SetEditLabelFont (AValue: TFont);       function  x3GetEditLabelFont ()          : TFont;       procedure x3SetEditLabelFocusFont (AValue: TFont);       function  x3GetEditLabelFocusFont ()     : TFont;       procedure x3SetEditLabelParentColor (FParentColor : BOOLEAN);       function  x3GetEditLabelParentColor ()   : BOOLEAN;       procedure x3SetEditLabelParentFont (FParentFont : BOOLEAN);       function  x3GetEditLabelParentFont  ()   : BOOLEAN;       procedure x3SetEditLabelParentBidiMode (FParentBidiMode: BOOLEAN);       function  x3GetEditLabelParentBidiMode (): BOOLEAN; the properties that start x3, modify the same  property  simultaneously for three components. x1,  idem but only one. However,  I needed any more. The code  was ugly and big. I decided to use the full set of them . My code, in previous post, is very clean and short, but it hangs up the IDE. Is necessary a default property editor for TLabeledEdit? Why not for TEdit? TEdit works properly, and -  I think - it has not  a default property editor. That one is what I do not understand Best Regards ---------------------------------------------------------------------- pusuni · 2014-02-22 10:56 Hi again!! I've got a problem with my new control: I don't understand the anchor commands. I'm trying to  put in the right-top corner inside a TPanel a Tlabel, and TLabel appears in the left-top corner inside of TPanel This is the code What's wrong? Code: [Select]unit Panel1; {$mode objfpc}{$H+} interface uses   Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls; type   TPanel1 = class(TPanel)   private     { Private declarations }     FLabel1                            : TLabel;   protected     { Protected declarations }   public     { Public declarations }     constructor Create(TheOwner: TComponent);    override;     destructor Destroy;                          override;   published     { Published declarations }     property Label1   : TLabel       read FLabel1;   end; procedure Register; implementation procedure Register; begin   RegisterComponents('Standard',[TPanel1]); end; constructor TPanel1.Create(TheOwner: TComponent); begin    inherited Create(TheOwner);    FLabel1 := TLabel.Create(Self);    FLabel1.Parent:= Self;    FLabel1.SetSubComponent(true);    FLabel1.ControlStyle := FLabel1.ControlStyle - [csNoDesignSelectable];    FLabel1.Name := 'Label1';    FLabel1.Caption := 'Label1';    FLabel1.AnchorParallel(akTop,0,Self);    FLabel1.AnchorSideRight.Control := Self;    FLabel1.AnchorSideRight.Side := asrLeft; end; destructor TPanel1.Destroy; begin    FLabel1.Free;    inherited Destroy; end; end.          Regards ---------------------------------------------------------------------- engkin · 2014-02-22 14:09 Quote from: pusuni on February 22, 2014, 11:56:18 amI'm trying to  put in the right-top corner inside a TPanel a Tlabel I used the Anchor Editor to see what it does in the lfm file. The result: Code: [Select]  FLabel1.AnchorSideTop.Control := Panel1;   FLabel1.AnchorSideRight.Control := Panel1;   FLabel1.AnchorSideRight.Side := asrRight;   FLabel1.Anchors := [akTop, akRight]; QuoteThis is the code What's wrong?By default FLabel1.Anchors has akTop and akLeft. With your code FLabel1.Width extends along the Panel but since the FLabel1.Alignment is taLeftJustify the text is going to show on the left side which gives the impression that it moved to the left instead of the intended direction. I guess. ---------------------------------------------------------------------- pusuni · 2014-02-22 15:51 Hi, engkin!! I've tested your code and it works properly (only I had to change 'Panel1' to 'Self') Another question: do you know if  there is a way to disable one/two parent's properties, in a child control ? Thanks again ---------------------------------------------------------------------- engkin · 2014-02-22 16:43 Quote from: pusuni on February 22, 2014, 04:51:55 pmAnother question: do you know if  there is a way to disable one/two parent's properties, in a child control ? Are you trying to remove properties inherited from a parent class? Are you trying to remove it from the Object Inspector? You can re-declare a property in another section. Which properties are you trying to disable and why? ---------------------------------------------------------------------- pusuni · 2014-02-23 13:44 Quote from: engkin on February 22, 2014, 05:43:17 pmAre you trying to remove properties inherited from a parent class? Yes Quote from: engkinAre you trying to remove it from the Object Inspector? Yes Quote from: engkinYou can re-declare a property in another section. I didn't know it. Quote from: engkinWhich properties are you trying to disable and why? If you look at the source code (the code  works ok) and you create a control with Panel1 new control, Code: [Select]unit Panel1; {$mode objfpc}{$H+} interface uses   Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls; type   TPanel1 = class(TPanel)   private     { Private declarations }     FLabel1                            : TLabel;     ColorTMP                           : TColor;     procedure ColorRojo (Sender : TObject);     procedure ColorOriginal (Sender : TObject);   protected     { Protected declarations }   public     { Public declarations }     constructor Create(TheOwner: TComponent);    override;     destructor Destroy;                          override;   published     { Published declarations }     property Label1   : TLabel       read FLabel1;   end; procedure Register; implementation procedure Register; begin   RegisterComponents('Standard',[TPanel1]); end; constructor TPanel1.Create(TheOwner: TComponent); begin    inherited Create(TheOwner);    FLabel1 := TLabel.Create(Self);    FLabel1.Parent:= Self;    FLabel1.SetSubComponent(true);    FLabel1.ControlStyle := FLabel1.ControlStyle - [csNoDesignSelectable];    FLabel1.Name := 'Label1';    FLabel1.Caption := 'Label1';    FLabel1.AnchorSideTop.Control := Self;    FLabel1.AnchorSideRight.Control := Self;    FLabel1.AnchorSideRight.Side := asrRight;    FLabel1.Anchors := [akTop, akRight];    OnMouseEnter := @ColorRojo;    OnMouseLeave  := @ColorOriginal; end; destructor TPanel1.Destroy; begin    FLabel1.Free;    inherited Destroy; end; procedure TPanel1.ColorRojo (Sender : TObject); begin    inherited; // OnMouseEnter;    ColorTMP := Color;    Color := clRed;    repaint; end; procedure TPanel1.ColorOriginal (Sender : TObject); begin    inherited; // OnMouseLeave;    Color := ColorTMP;    repaint; end; end.The OnMouseEnter and OnMouseLeave events in the object inspector appear "unpublished" . I think they should not appear , because I've added code for these events . I think the best will be disable in the parent class Regards ---------------------------------------------------------------------- taazz · 2014-02-23 14:05 1) never ever use the events from your inherited components there are methods you can override usually they have a name like DoMouseEnter, DoMouseLeave etc and the only thing they do is to call the event if assigned. 2) try to find a parent that does not have those events or properties published in your case that would be TCustomPanel. Take a look on TPanel to see which properties are published and copy from there which ever you want or all of them ---------------------------------------------------------------------- howardpc · 2014-02-23 14:09 You can't reduce the visibility of a method or property by redeclaring it. You can only increase its visibility by redeclaration. This is why many VCL/LCL components are part of a hierarchy which includes a TCustomxxxx class which publishes very little (or nothing). Then component designers can inherit from a TCustomxxx to build their descendant and publish only the properties they want. Since you decend from TPanel, your OnMousexxx methods are already published in the ancestor, and cannot be unpublished. Even putting them in a private section has no effect at all on their publication, since RTTI is already generated for them in their ancestor's declaration. You can avoid this by descending from TCustomPanel as taazz says, and not publishing those properties, which will prevent them from showing up in the Object Inspector (they will still be public, of course, and so accessible in code). ---------------------------------------------------------------------- pusuni · 2014-02-23 15:14 Thank very much for all advices ---------------------------------------------------------------------- engkin · 2014-02-23 18:17 Quote from: howardpc on February 23, 2014, 03:09:09 pmYou can't reduce the visibility of a method or property by redeclaring it. Thank you. I'm unaware of this. I'll try to find it in the docs.