Recent

Author Topic: Array of TPersistant Objects for Design Time  (Read 926 times)

SandyG

  • Jr. Member
  • **
  • Posts: 78
Array of TPersistant Objects for Design Time
« on: June 16, 2024, 12:57:11 am »
Not sure if this is possible,

I have an object that inherits from TPersistant. This works as a custom class that can be edited in the property inspector. Normal stuff.

The question is it possible to have an ARRAY of these object and still have the design time property inspector work? I can get it to compile just fine but will crash  Lazarus when I install the component (even with a fresh project not yet using the component, as soon as I add it to the form it crashes the works)

Code: Pascal  [Select][+][-]
  1. // lots of code removed
  2.  
  3.   TDTCustomThemedGauge = class(TDTBaseAnalogDevice)
  4.   private
  5.     FLedArray: Array[0..7] of TDTRangeCheckLedSettings; // want to have an array of these in the property inspector at design time, this inherits from TPersistent
  6. ...
  7.     Procedure SetLedArray(AIndex: Integer; AValue: TDTRangeCheckLedSettings);
  8.     Function GetLedArray(AIndex: Integer): TDTRangeCheckLedSettings;
  9.  
  10.     { Private declarations }
  11.   protected
  12.     { Protected declarations }
  13.     Property LedArray[AIndex: Integer]:TDTRangeCheckLedSettings Read GetLedArray Write SetLedArray;
  14.  
  15.   public
  16.     { Public declarations }
  17. ...
  18.   end;
  19.  
  20. ...
  21.  
  22. Procedure TDTCustomThemedGauge.SetLedArray(AIndex:Integer; AValue: TDTRangeCheckLedSettings);
  23. begin
  24.   FLedArray[AIndex] := AValue; // OK for a descendant of a TPersistent or have to do it member var by member var??
  25. end;
  26.  
  27. Function TDTCustomThemedGauge.GetLedArray(AIndex:Integer): TDTRangeCheckLedSettings;
  28. begin
  29.   Result := FLedArray[AIndex];
  30. end;
  31. ...

Can something like this be done or is it out of scope for the way the design time property inspector works.

Sandy

jamie

  • Hero Member
  • *****
  • Posts: 6369
Re: Array of TPersistant Objects for Design Time
« Reply #1 on: June 16, 2024, 02:39:42 am »
I think I have an idea of what you want.

Please look at the THeaderCOntrol on the common controls tab and look at its sources.

It has a Section Property that gives you a TreeView structure of header items added in the OI.

You can examine how the OI manages this.
The only true wisdom is knowing you know nothing

SandyG

  • Jr. Member
  • **
  • Posts: 78
Re: Array of TPersistant Objects for Design Time
« Reply #2 on: June 16, 2024, 04:59:33 pm »
Thanks, I'll take a look.

Sandy

alpine

  • Hero Member
  • *****
  • Posts: 1161
Re: Array of TPersistant Objects for Design Time
« Reply #3 on: June 16, 2024, 07:02:30 pm »
Quote
The question is it possible to have an ARRAY of these object and still have the design time property inspector work?
Use TOwnedCollection instead. That's the way the object inspector works.
"I'm sorry Dave, I'm afraid I can't do that."
—HAL 9000

SandyG

  • Jr. Member
  • **
  • Posts: 78
Re: Array of TPersistant Objects for Design Time
« Reply #4 on: June 26, 2024, 04:08:00 am »
Just starting to get back at this,

Why TOwnedCollection, I see in the THeaderControl using TCollection?

Sandy

alpine

  • Hero Member
  • *****
  • Posts: 1161
Re: Array of TPersistant Objects for Design Time
« Reply #5 on: June 26, 2024, 09:59:35 am »
Just starting to get back at this,

Why TOwnedCollection, I see in the THeaderControl using TCollection?

Sandy
Same, but you should override GetOwner function to return the owner component. In the TOwnedCollection you can give it to the constructor.
"I'm sorry Dave, I'm afraid I can't do that."
—HAL 9000

 

TinyPortal © 2005-2018