Recent

Author Topic: [Solved]Creating custom property editor  (Read 3733 times)

AlphaHaxor

  • Newbie
  • Posts: 4
[Solved]Creating custom property editor
« on: October 19, 2018, 07:32:26 pm »
I have created a custom object - "ChessPiece" - that has 2 custom string properties: "PieceType" and "PieceOwner". I have tested them by instantiating them and giving their values to label captions and they worked. However I was unable to figure out how to create a property editor so that these properties would appear in object inspector. Would anyone be so kind and help me with this issue?

Code: Pascal  [Select][+][-]
  1. unit ChessPiece;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, ExtCtrls;
  9.  
  10. type
  11.   TChessPiece = class(TImage)
  12.   private
  13.     GetPieceType: string;
  14.     GetPieceOwner: string;
  15.     procedure SetPieceType(AValue: string);
  16.     procedure SetPieceOwner(AValue: string);
  17.   public
  18.     //TChessPiece properties
  19.     property PieceType: string read GetPieceType write SetPieceType;
  20.     property PieceOwner: string read GetPieceOwner write GetPieceOwner;
  21.   published
  22.     //TImage properties
  23.     property Align;
  24.     property Anchors;
  25.     property AutoSize;
  26.     property BorderSpacing;
  27.     property Center;
  28.     property Constraints;
  29.     property DragCursor;
  30.     property DragMode;
  31.     property Enabled;
  32.     property OnChangeBounds;
  33.     property OnClick;
  34.     property OnDblClick;
  35.     property OnDragDrop;
  36.     property OnDragOver;
  37.     property OnEndDrag;
  38.     property OnMouseDown;
  39.     property OnMouseEnter;
  40.     property OnMouseLeave;
  41.     property OnMouseMove;
  42.     property OnMouseUp;
  43.     property OnMouseWheel;
  44.     property OnMouseWheelDown;
  45.     property OnMouseWheelUp;
  46.     property OnPaint;
  47.     property OnPictureChanged;
  48.     property OnResize;
  49.     property OnStartDrag;
  50.     property ParentShowHint;
  51.     property Picture;
  52.     property PopupMenu;
  53.     property Proportional;
  54.     property ShowHint;
  55.     property Stretch;
  56.     property Transparent;
  57.     property Visible;
  58.   end;
  59.  
  60. procedure Register;
  61.  
  62. implementation
  63.  
  64. procedure TChessPiece.SetPieceType(AValue: string);
  65. begin
  66.   if GetPieceType=AValue then Exit;
  67.   GetPieceType:=AValue;
  68. end;
  69.  
  70. procedure TChessPiece.SetPieceOwner(AValue: string);
  71. begin
  72.   if GetPieceOwner=AValue then Exit;
  73.   GetPieceOwner:=AValue;
  74. end;
  75.  
  76. procedure Register;
  77. begin
  78.   {$I chesspiece_icon.lrs}
  79.   RegisterComponents('Additional',[TChessPiece]);
  80. end;
  81.  
  82. end.
« Last Edit: October 19, 2018, 09:38:41 pm by AlphaHaxor »

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: Creating custom property editor
« Reply #1 on: October 19, 2018, 07:40:45 pm »
Move those two properties to published section.
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/

AlphaHaxor

  • Newbie
  • Posts: 4
Re: Creating custom property editor
« Reply #2 on: October 19, 2018, 08:10:53 pm »
I have done so but the property is nowhere to be found...

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: Creating custom property editor
« Reply #3 on: October 19, 2018, 08:30:19 pm »
Your component must be part of package which is installed to IDE and you have to rebuild IDE after this change to make those properties appear in OI.
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/

AlphaHaxor

  • Newbie
  • Posts: 4
Re: Creating custom property editor
« Reply #4 on: October 19, 2018, 08:32:50 pm »
How do I rebuild IDE?

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Creating custom property editor
« Reply #5 on: October 19, 2018, 08:44:33 pm »
Use the Package->Open package file (.lpk)
or
Package-> Open recent package
to locate the package containing your component. This opens the Package Editor. Test your package compiles OK using the Compile toolbutton. Then click the Use toolbutton, and Install. The Package Editor will ask if you want to rebuild the IDE in order to install the component. Click OK.

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: Creating custom property editor
« Reply #6 on: October 19, 2018, 08:48:29 pm »
Tools -> Configure Build Lazarus ... -> Build

is another way how to rebuild IDE. But in this case, follow howardpc's advice above.
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/

AlphaHaxor

  • Newbie
  • Posts: 4
Re: Creating custom property editor
« Reply #7 on: October 19, 2018, 09:37:26 pm »
Finally! It's working! Thank you for your help. I was scratching my head on this for hours. With this new object I will be able to improve my game significantly.

Code: Pascal  [Select][+][-]
  1. unit ChessPiece;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, ExtCtrls;
  9.  
  10. type
  11.   TChessPiece = class(TImage)
  12.   private
  13.     GetPieceType: string;
  14.     GetPieceOwner: string;
  15.     GetPieceHasMoved: boolean;
  16.     procedure SetPieceType(AValue: string);
  17.     procedure SetPieceOwner(AValue: string);
  18.     procedure SetPieceHasMoved(AValue: boolean);
  19.   public
  20.  
  21.   published
  22.     property PieceType: string read GetPieceType write SetPieceType;
  23.     property PieceOwner: string read GetPieceOwner write SetPieceOwner;
  24.     property PieceHasMoved: boolean read GetPieceHasMoved write SetPieceHasMoved;
  25.   end;
  26.  
  27. procedure Register;
  28.  
  29. implementation
  30.  
  31. procedure TChessPiece.SetPieceType(AValue: string);
  32. begin
  33.   if GetPieceType=AValue then Exit;
  34.   GetPieceType:=AValue;
  35. end;
  36.  
  37. procedure TChessPiece.SetPieceOwner(AValue: string);
  38. begin
  39.   if GetPieceOwner=AValue then Exit;
  40.   GetPieceOwner:=AValue;
  41. end;
  42.  
  43. procedure TChessPiece.SetPieceHasMoved(AValue: boolean);
  44. begin
  45.   if GetPieceHasMoved=AValue then Exit;
  46.   GetPieceHasMoved:=AValue;
  47. end;
  48.  
  49. procedure Register;
  50. begin
  51.   {$I chesspiece_icon.lrs}
  52.   RegisterComponents('Additional',[TChessPiece]);
  53. end;
  54.  
  55.  
  56. end.

P.S. The declarations of TImage properties in my previous code were unnecessary as my object already uses TImage as a parent object.

 

TinyPortal © 2005-2018