我想创建一组属性(可扩展属性)我将记录类型和我的属性的设置类型定义为记录。但该属性不会出现在对象检查器中,但在运行时我可以访问该属性。
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;
我该怎么办? 请帮帮我
答案 0 :(得分:1)
要使结构化类型可流化并在设计器中进行设置,类型必须来自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;