Recent

Author Topic: [Solved]How can I make a descendent of a TCustomLabeledEdit  (Read 332 times)

bobonwhidbey

  • Hero Member
  • *****
  • Posts: 592
    • Double Dummy Solver - free download
[Solved]How can I make a descendent of a TCustomLabeledEdit
« on: April 01, 2023, 06:50:51 pm »
I'm trying to make a new component but
     TMyComp = class(TCustomLabelEdit)
doesn't work even though ExtCtrls is in my Uses clause.
« Last Edit: April 01, 2023, 08:21:26 pm by bobonwhidbey »
Lazarus 3.0RC2, FPC 3.2.2 x86_64-win64-win32/win64

wp

  • Hero Member
  • *****
  • Posts: 11910
Re: How can I make a descendent of a TCustomLabeledEdit
« Reply #1 on: April 01, 2023, 07:00:57 pm »
What isn't working? And what should be different from TCustomLabeledEdit?

The following demo is working. It creates a TMyComp component as descendant of TCustomLabeledEdit in which the label font color defaults to red.

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls;
  9.  
  10. type
  11.   TMyComp = class(TCustomLabeledEdit)
  12.   public
  13.     constructor Create(AOwner: TComponent); override;
  14.   end;
  15.  
  16.   { TForm1 }
  17.  
  18.   TForm1 = class(TForm)
  19.     procedure FormCreate(Sender: TObject);
  20.   private
  21.     myComp: TMyComp;
  22.  
  23.   public
  24.  
  25.   end;
  26.  
  27. var
  28.   Form1: TForm1;
  29.  
  30. implementation
  31.  
  32. {$R *.lfm}
  33.  
  34. constructor TMyComp.Create(AOwner: TComponent);
  35. begin
  36.   inherited;
  37.   EditLabel.Font.Color := clRed;
  38. end;
  39.  
  40. { TForm1 }
  41.  
  42. procedure TForm1.FormCreate(Sender: TObject);
  43. begin
  44.   myComp := TMyComp.Create(self);
  45.   myComp.Left := 8;
  46.   myComp.Top := 24;
  47.   myComp.Width := 200;
  48.   myComp.Parent := self;
  49.   myComp.EditLabel.Caption := 'My new component';
  50.   myComp.Text := 'This is a test.';
  51. end;
« Last Edit: April 01, 2023, 07:03:40 pm by wp »

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: How can I make a descendent of a TCustomLabeledEdit
« Reply #2 on: April 01, 2023, 07:02:33 pm »
It is "Labeled". A typo, I guess. And yes, it is in ExtCtrls.
Code: Pascal  [Select][+][-]
  1.      TMyComp = class(TCustomLabeledEdit)
  2.  
Otherwise I cannot imagine how it cannot be subclassed.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

bobonwhidbey

  • Hero Member
  • *****
  • Posts: 592
    • Double Dummy Solver - free download
Re: How can I make a descendent of a TCustomLabeledEdit
« Reply #3 on: April 01, 2023, 08:21:11 pm »
Thanks Blaazen....just a dumb typo  :'(
Lazarus 3.0RC2, FPC 3.2.2 x86_64-win64-win32/win64

 

TinyPortal © 2005-2018