Recent

Author Topic: Custom Component  (Read 1899 times)

JimKueneman

  • Full Member
  • ***
  • Posts: 220
Custom Component
« on: June 25, 2019, 06:10:07 am »
It has been a while since I have done this but I am writing a custom component.  In that component I have created a sub class to group like properties in the object inspector.

Code: Pascal  [Select][+][-]
  1.  
  2.   TVirtualExpandProperties = class(TComponent)
  3.   private
  4.     FImageIndexCollapsed: Integer;
  5.     FImageIndexExpanded: Integer;
  6.     FImagePosition: TExpandImagePostition;
  7.     FImages: TImageList;
  8.     FOwnerListview: TCustomVirtualListview;
  9.   protected
  10.     property OwnerListview: TCustomVirtualListview read FOwnerListview;
  11.   public
  12.     constructor Create(AOwner: TComponent);
  13.     destructor Destroy; override;
  14.   published
  15.     property Images: TImageList read FImages write FImages;
  16.     property ImageIndexExpanded: Integer read FImageIndexExpanded write FImageIndexExpanded;
  17.     property ImageIndexCollapsed: Integer read FImageIndexCollapsed write FImageIndexCollapsed;
  18.     property ImagePosition: TExpandImagePostition read FImagePosition write FImagePosition;
  19.   end;
  20.  

and in the component I create it and publish it in the TVirtualListview class which is what is installed in the IDE

Code: Pascal  [Select][+][-]
  1. constructor TCustomVirtualListview.Create(AOwner: TComponent);
  2. begin
  3.   inherited Create(AOwner);
  4.   .......
  5.  
  6.   FExpandProperties := TVirtualExpandProperties.Create(Self);
  7.   ExpandProperties.FOwnerListview := Self;
  8. end;
  9.  

I also register the class for the streaming system:

Code: Pascal  [Select][+][-]
  1.  
  2. initialization
  3.   RegisterClass(TVirtualExpandProperties);
  4.  
  5. end.      
  6.  

It shows up just fine in the object inspector but when I run the program the changed values in this sub-object are back to default and if I show the form as text this component is not being streamed.... What am I missing.

Thanks,
Jim

BeanzMaster

  • Sr. Member
  • ****
  • Posts: 268
Re: Custom Component
« Reply #1 on: June 25, 2019, 02:56:32 pm »
Hi

Try to uses TPersistent instead of TComponent for those things

Best regards

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Custom Component
« Reply #2 on: June 26, 2019, 01:04:37 pm »
To have its proerties streamed your OwnerListview instance must be published, not protected.

 

TinyPortal © 2005-2018