Summary
DefClassAttribute can be applied to object property to specify the default class of property value.
Syntax
DefClassAttribute = class(TClassBaseAttr);
Remarks
Due to inheritance the run-time class of object property value can be different from property compile-time type; value class can be, actually, a sub-class of the property type. In this case serializer have to write object class name to be able to create an object of correct class during de-serialization. From the other side, serializer will not write object class name, if the object class is equal to property type; this makes output more readable.
However, if usual value class is different from property type, DefClassAttribute can be used to change the default class, used by serializer for comparison.
Examples
| Delphi | Copy Code
|
|---|---|
type
TSubObject = class
end;
TMyObject = class
private
FSubObj: TObject; // TSubObject value is really assigned.
public
[DefClass(TSubObject)]
property SubObj: TObject read FSubObj write FSubObj;
end; | |