0

I want to create a group of property (Expandable Property) I Define a Record Type and Set Type of My Property as a record. but That property dos not Appears in object inspector but on run time I can access to that property.

  type
  GageProperty = Record
    MaxValue:Real;
    Color1:TColor;
    Color2:TColor;
    DividerLength:Integer;
    DownLimit:Real;
    FloatingPoint:Integer;
    Frame:Boolean;
    GageFont:TFont;
    GradiantStyle:GradStyle;
    Height:Integer;
    Width:Integer;
    Left:Integer;
    MinValue:Real;
    NeedleColor:Tcolor;
    Sector1Color:TColor;
    Sector2Color:TColor;
    Sector3Color:TColor;
    SignalFont:TFont;
    SignalNmae:String;
    Step:Integer;
    SubStep:Integer;
    Thickness:Integer;
    Top:Integer;
    UpLimit:Real;
    ValueUnit:String;
  End;
  TGasTurbine = class(TPanel)
  private
    { Private declarations }
    FGageProp:GageProperty;
    Procedure SetGageProp(Const Value:GageProperty);
  published
    { Published declarations }
    Property GageProp: GageProperty Read FGageProp Write SetGageProp;

What should i Do? Please Help me

Fayyaz
  • 199
  • 2
  • 13

1 Answers1

1

For a structured type to be streamable and to be set in the designer, the type has to descend from TPersistent:

type
  TGage = class(TPersistent)
  public
    MaxValue: Real;
    Color1: TColor;
    Color2: TColor;
    procedure Assign(Source: TPersistent); override;
  end;

  TGasTurbine = class(TPanel)
  private
    FGage: TGage;
    procedure SetGage(Value: TGage);
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  published
    property Gage: TGage read FGage write SetGage;
  end;    

procedure TGage.Assign(Source: TPersistent);
begin
  if Source is TGage then
  begin
    MaxValue := TGage(Source).MaxValue;
    Color1 := TGage(Source).Color1;
    Color2 := TGage(Source).Color2;
  end
  else
    inherited Assign(Source);
end;

constructor TGasTurbine.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FGage := TGage.Create;
end;

destructor TGasTurbine.Destroy;
begin
  FGage.Free;
  inherited Destroy;
end;

procedure TGasTurbine.SetGage(Value: TGage);
begin
  FGage.Assign(Value);
end;
NGLN
  • 43,011
  • 8
  • 105
  • 200
  • There is an error in your code. In order to expose specific fields of TGauge to object inspector you need to make published properties for them. Othervise object inspector will only allow you assigning of the whole TGauge class at once. And as far as I know that only works with already placed components (Object Inspector shows you a list of available components). Also since TGauge is an internal class of TGasTurbine in this examle it should probably be set as read-only so that someone doesen't destroy it prematurely. – SilverWarior Mar 29 '15 at 13:53