Recent

Author Topic: [SOLVED]Custom Component/ Component properties in property editor  (Read 7568 times)

Never

  • Sr. Member
  • ****
  • Posts: 409
  • OS:Win7 64bit / Lazarus 1.4
[SOLVED]Custom Component/ Component properties in property editor
« on: September 30, 2014, 03:29:09 pm »
Code: [Select]
Ttest=class(TPanel)
private
Edit: TEdit;

    function func_GetColor(): TColor;//override;
    procedure proc_SetColor(AColor: TColor);//override;
  public 
property Color:TColor read func_GetColor write proc_SetColor;
end;


function Ttest.func_GetColor: TColor;
begin
  Result:=Edit_.Color;
end;
procedure Register;

implementation
procedure Register;
begin
  RegisterComponents('Standard',[TTest]);
end; 
procedure Ttest.proc_SetColor(AColor: TColor);
begin
 //inherited SetColor(AColor);
 Edit.Color:=AColor;
 
end;
how should i code these properties
((color,font,border etc)properties that are in the TPanel for ex. but will be used on a child control of TPanel) in order to keep the functionality of the lazarus property editor
and apply the value to the desired child control at design time
i tried to set the name to SetColor and override the procedure but no luck
« Last Edit: September 30, 2014, 08:56:53 pm by Never »
Νέπε Λάζαρε λάγγεψων οξωκά ο φίλοσ'ς αραεύσε

Blaazen

  • Hero Member
  • *****
  • Posts: 3238
  • POKE 54296,15
    • Eye-Candy Controls
Re: Custom Component/ Component properties in property editor
« Reply #1 on: September 30, 2014, 06:01:52 pm »
If you define property Color this way, it will cover the original Color property defined somewhere in TControl.
You should rather catch the message method CM_COLORCHANGED:
Code: [Select]
procedure CMColorChanged(var {%H-}Message: TLMessage); message CM_COLORCHANGED;Note that {%H-} is there only for the case you dont need the Message parameter, to suppress compiler hint.
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/

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1260
Re: Custom Component/ Component properties in property editor
« Reply #2 on: September 30, 2014, 06:06:14 pm »
Note that {%H-} is there only for the case you dont need the Message parameter, to suppress compiler hint.

Brilliant!   Thanks for the tip, heading off to paste that into a MILLION places :-)
Lazarus Trunk/FPC Trunk on Windows [7, 10]
  Have you tried searching this forum or the wiki?:   http://wiki.lazarus.freepascal.org/Alternative_Main_Page
  BOOKS! (Free and otherwise): http://wiki.lazarus.freepascal.org/Pascal_and_Lazarus_Books_and_Magazines

Fred vS

  • Hero Member
  • *****
  • Posts: 3168
    • StrumPract is the musicians best friend
Re: Custom Component/ Component properties in property editor
« Reply #3 on: September 30, 2014, 06:12:18 pm »
Quote
procedure CMColorChanged(var {%H-}Message: TLMessage); message CM_COLORCHANGED;
Note that {%H-} is there only for the case you dont need the Message parameter, to suppress compiler hint.

@ Blaazen => Big Wow, one more time... => Super many thanks.  ;)

Fred
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Custom Component/ Component properties in property editor
« Reply #4 on: September 30, 2014, 06:34:13 pm »
Note that {%H-} is there only for the case you dont need the Message parameter, to suppress compiler hint.
...
Brilliant!   Thanks for the tip, heading off to paste that into a MILLION places :-)

If you use the trunk version of Lazarus, when you see a build/compile message
Code: [Select]
Hint: Parameter "aParam" not used
which you would rather ignore thereafter, you can right click on the message and get an option for the IDE either to automatically insert a (%H-) at the appropriate place; or for that error message to be generally suppressed. Lazarus useability just keeps getting better.
Although this is in trunk, at the rate of recent releases, it won't be long before we see this in the next release version.

Never

  • Sr. Member
  • ****
  • Posts: 409
  • OS:Win7 64bit / Lazarus 1.4
Re: Custom Component/ Component properties in property editor
« Reply #5 on: September 30, 2014, 06:40:38 pm »
Thank you very much @Blaazen
this is working fine when the program is running but it is also not working in design time
also what about the other properties? fonts,text,caption etc.
in the above example i added a text property Tcaption
a boolean property and some other using different types int, string, etc.
and expected to see them in the property editor but they are not there.
i'm sure i'm missing something here
Νέπε Λάζαρε λάγγεψων οξωκά ο φίλοσ'ς αραεύσε

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1260
Re: Custom Component/ Component properties in property editor
« Reply #6 on: September 30, 2014, 06:40:46 pm »
If you use the trunk version of Lazarus, when you see a build/compile message
Code: [Select]
Hint: Parameter "aParam" not used
which you would rather ignore thereafter, you can right click on the message and get an option for the IDE either to automatically insert a (%H-) at the appropriate place; or for that error message to be generally suppressed. Lazarus useability just keeps getting better.

Nice :)  I saw various mails about the new message window functionality - but missed this one.
Lazarus Trunk/FPC Trunk on Windows [7, 10]
  Have you tried searching this forum or the wiki?:   http://wiki.lazarus.freepascal.org/Alternative_Main_Page
  BOOKS! (Free and otherwise): http://wiki.lazarus.freepascal.org/Pascal_and_Lazarus_Books_and_Magazines

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1260
Re: Custom Component/ Component properties in property editor
« Reply #7 on: September 30, 2014, 06:43:15 pm »
Thank you very much @Blaazen
this is working fine when the program is running but it is also not working in design time
also what about the other properties? fonts,text,caption etc.
in the above example i added a text property Tcaption
a boolean property and some other using different types int, string, etc.
and expected to see them in the property editor but they are not there.
i'm sure i'm missing something here

Quote
Code: [Select]
Ttest=class(TPanel)
private
Edit: TEdit;

    function func_GetColor(): TColor;//override;
    procedure proc_SetColor(AColor: TColor);//override;
  public 
property Color:TColor read func_GetColor write proc_SetColor;
end;

You're declaring the property as Public.  To get it into the Object Inspector, you need to declare it Published

Code: [Select]
Ttest=class(TPanel)
private
Edit: TEdit;

    function func_GetColor(): TColor;//override;
    procedure proc_SetColor(AColor: TColor);//override;
  Published                          // <----  This was Public, now it's Published.... 
property Color:TColor read func_GetColor write proc_SetColor;
end;
Lazarus Trunk/FPC Trunk on Windows [7, 10]
  Have you tried searching this forum or the wiki?:   http://wiki.lazarus.freepascal.org/Alternative_Main_Page
  BOOKS! (Free and otherwise): http://wiki.lazarus.freepascal.org/Pascal_and_Lazarus_Books_and_Magazines

Never

  • Sr. Member
  • ****
  • Posts: 409
  • OS:Win7 64bit / Lazarus 1.4
Re: Custom Component/ Component properties in property editor
« Reply #8 on: September 30, 2014, 07:09:41 pm »
@Mike.Cornflake thank you
i move them to published also but still are not appearing in the property editor it must be something else i'm missing
and got [SIGSEGV] when i try to override the color procedure

Code: [Select]
Ttest=class(TPanel)
private
Edit: TEdit;
    function func_GetItems: Integer;
    procedure proc_SetItems(param_Items: Integer);
    function func_GetColor(): TColor;//override;
    procedure SetColor(AColor: TColor);override;
  published 
property Color:TColor read func_GetColor write SetColor;
property Items:Integer read func_GetItems write proc_SetItems;
end;

procedure Register;

implementation
procedure Register;
begin
  RegisterComponents('Standard',[TTest]);
end;
 
procedure Ttest.SetColor(AColor: TColor);
begin
 inherited SetColor(AColor);
------------------------------------------------------------------------------------
 Edit.Color:=AColor;<--------------when i add this i got SIGSEGV
 -------------------------------------------------------------------------------------
end;
« Last Edit: September 30, 2014, 07:13:38 pm by Never »
Νέπε Λάζαρε λάγγεψων οξωκά ο φίλοσ'ς αραεύσε

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: Custom Component/ Component properties in property editor
« Reply #9 on: September 30, 2014, 07:20:51 pm »
and got [SIGSEGV] when i try to override the color procedure
You did not create an instance of TEdit. The class variable Edit is not valid, yet.

Blaazen

  • Hero Member
  • *****
  • Posts: 3238
  • POKE 54296,15
    • Eye-Candy Controls
Re: Custom Component/ Component properties in property editor
« Reply #10 on: September 30, 2014, 07:30:59 pm »
Quote
also what about the other properties? fonts,text,caption etc.
You can find relevant message method or override existing implementation.
Code: [Select]
procedure CMBiDiModeChanged(var {%H-}Message: TLMessage); message CM_BIDIMODECHANGED;
procedure CMParentColorChanged(var Message: TLMessage); message CM_PARENTCOLORCHANGED;
procedure FontChanged(Sender: TObject); override;
procedure TextChanged; override;
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/

Blaazen

  • Hero Member
  • *****
  • Posts: 3238
  • POKE 54296,15
    • Eye-Candy Controls
Re: Custom Component/ Component properties in property editor
« Reply #11 on: September 30, 2014, 07:46:39 pm »
I have to add one warning about message methods: some of them are implemented in ancestor so you have to call inherited method:
Code: [Select]
procedure TDerivedComponent.CMParentColorChanged(var Message: TLMessage);
begin
  inherited CMParentColorChanged(Message);
  //your code
end;
Unlike "normal" virtual methods, Lazarus does not add call of inherited automatically. I reported it but it is not easy to implement (see http://bugs.freepascal.org/view.php?id=24792).
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/

Never

  • Sr. Member
  • ****
  • Posts: 409
  • OS:Win7 64bit / Lazarus 1.4
Re: Custom Component/ Component properties in property editor
« Reply #12 on: September 30, 2014, 07:53:46 pm »
an update
by setting [ParentColor:=True; ] for the Edit i can achive the goal at runtime

without messup with the Color property

But not at design time

@Blaazen thank you i will read them
Edit:yes Blaazen when overriding i use this its nice because you can call inherited before or after your code
@engkin you are right i have to find a way to prevent this
« Last Edit: September 30, 2014, 07:56:31 pm by Never »
Νέπε Λάζαρε λάγγεψων οξωκά ο φίλοσ'ς αραεύσε

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1260
Re: Custom Component/ Component properties in property editor
« Reply #13 on: September 30, 2014, 08:25:29 pm »
@Mike.Cornflake thank you
i move them to published also but still are not appearing in the property editor it must be something else i'm missing

You won't see any changes in the OI until you rebuild Lazarus.

If you did rebuild Lazarus, then sorry - no idea.
Lazarus Trunk/FPC Trunk on Windows [7, 10]
  Have you tried searching this forum or the wiki?:   http://wiki.lazarus.freepascal.org/Alternative_Main_Page
  BOOKS! (Free and otherwise): http://wiki.lazarus.freepascal.org/Pascal_and_Lazarus_Books_and_Magazines

Never

  • Sr. Member
  • ****
  • Posts: 409
  • OS:Win7 64bit / Lazarus 1.4
Re: Custom Component/ Component properties in property editor
« Reply #14 on: September 30, 2014, 08:56:23 pm »
@Mike.Cornflake thank you so much
i removed the color property
just the parent color=true
and the other properties showed up also
and everything works as excpected after rebuilding the ide

how i missed this!?

if possible will you please point me where is this documented?
Νέπε Λάζαρε λάγγεψων οξωκά ο φίλοσ'ς αραεύσε

 

TinyPortal © 2005-2018