Castle Game Engine: X3DNodes: Class TSFNode

# Class TSFNode
Description | Hierarchy | Fields | Methods | Properties
## Unit X3DNodes ## Declaration `type TSFNode = class(TX3DSingleField)` ## Description VRML/X3D field holding a reference to a single node. It's defined in this unit, not in X3DFields, since it uses TX3DNode definition. NULL value of the field is indicated by Value field = nil. Note that we store AllowedChildren list, which is a list of classes allowed as a Value (also nil is always allowed). But this is used only to produce warnings for a user. You should never assert that Value actually is one the requested classes. We want to keep here even not allowed items, because we want operation "read from VRML file + write to VRML file" to be as non-destructible as possible. So if user wrote invalid class hierarchy, we will output this invalid class hierarchy. ## Hierarchy TPersistent TNonRefCountedInterfacedPersistent TX3DFileItem TX3DFieldOrEvent TX3DField TX3DSingleField TSFNode ## Overview ### Methods
| `constructor CreateUndefined(AParentNode: TX3DFileItem; const AName: string; const AExposed: boolean); override;`
| `constructor Create(AParentNode: TX3DNode; const AName: string; const AAllowedChildrenClasses: array of TX3DNodeClass; AValue: TX3DNode = nil); overload;`
| `constructor Create(AParentNode: TX3DNode; const AName: string; AAllowedChildrenClasses: TX3DNodeClassesList; AValue: TX3DNode = nil); overload;`
| `constructor Create(AParentNode: TX3DNode; const AName: string; AnAllowedChildrenInterface: TGUID; AValue: TX3DNode = nil); overload;`
| `destructor Destroy; override;`
| `procedure ParseValue(Lexer: TX3DLexer; Reader: TX3DReader); override;`
| `procedure ParseXMLAttribute(const AttributeValue: string; Reader: TX3DReader); override;`
| `procedure ParseXMLElement(Element: TDOMElement; Reader: TX3DReader); override;`
| `function EqualsDefaultValue: boolean; override;`
| `function Equals(SecondValue: TX3DField; const EqualityEpsilon: Double): boolean; override;`
| `procedure Assign(Source: TPersistent); override;`
| `procedure AssignValue(Source: TX3DField); override;`
| `procedure AssignDefaultValueFromValue; override;`
| `class function TypeName: string; override;`
| `procedure WarningIfChildNotAllowed(Child: TX3DNode);`
| `function ChildAllowed(Child: TX3DNode): boolean;`
| `function CurrentChildAllowed: boolean;`
| `procedure EnumerateValid(Func: TEnumerateChildrenFunction);`
### Properties
| `property DefaultValue: TX3DNode read FDefaultValue write SetDefaultValue;`
| `property DefaultValueExists: boolean read FDefaultValueExists write SetDefaultValueExists default false;`
| `property Value: TX3DNode read FValue write SetValue;`
| `property ParentNode: TX3DNode read FParentNode;`
## Description ### Methods
| `constructor CreateUndefined(AParentNode: TX3DFileItem; const AName: string; const AExposed: boolean); override;`
Construct a field allowing any children class. Suitable only for special cases. For example, in instantiated prototypes, we must initially just allow all children, otherwise valid prototypes with SFNode/MFNode would cause warnings when parsing.
| `constructor Create(AParentNode: TX3DNode; const AName: string; const AAllowedChildrenClasses: array of TX3DNodeClass; AValue: TX3DNode = nil); overload;`
| `constructor Create(AParentNode: TX3DNode; const AName: string; AAllowedChildrenClasses: TX3DNodeClassesList; AValue: TX3DNode = nil); overload;`
Constructor that takes a list of allowed children classes. Note that we copy the contents of AAllowedChildrenClasses, not the reference.
| `constructor Create(AParentNode: TX3DNode; const AName: string; AnAllowedChildrenInterface: TGUID; AValue: TX3DNode = nil); overload;`
Constructor that allows as children any implementor of given interface.
| `destructor Destroy; override;`
| `procedure ParseValue(Lexer: TX3DLexer; Reader: TX3DReader); override;`
| `procedure ParseXMLAttribute(const AttributeValue: string; Reader: TX3DReader); override;`
| `procedure ParseXMLElement(Element: TDOMElement; Reader: TX3DReader); override;`
| `function EqualsDefaultValue: boolean; override;`
| `function Equals(SecondValue: TX3DField; const EqualityEpsilon: Double): boolean; override;`
| `procedure Assign(Source: TPersistent); override;`
| `procedure AssignValue(Source: TX3DField); override;`
| `procedure AssignDefaultValueFromValue; override;`
| `class function TypeName: string; override;`
| `procedure WarningIfChildNotAllowed(Child: TX3DNode);`
Checks is the Child allowed as a value of this SFNode, and makes OnWarning if not. Check is allowed is done looking at AllowedChildrenAll and AllowedChildren properties. Child must not be `Nil`. OnWarning message will suggest that this Child is used as value of this node. In other words, you should only pass as Child a node that you want to assign as Value to this field, otherwise OnWarning message will be a little unsensible.
| `function ChildAllowed(Child: TX3DNode): boolean;`
| `function CurrentChildAllowed: boolean;`
| `procedure EnumerateValid(Func: TEnumerateChildrenFunction);`
Calls Func for our Value, assuming it's set (non-nil) and valid (allowed by ChildAllowed). The main use for this is to simplify implementation of TX3DNode.DirectEnumerateActive overrides in TX3DNode descendants.
### Properties
| `property DefaultValue: TX3DNode read FDefaultValue write SetDefaultValue;`
Default value of SFNode field. While X3D specification says for all SFNode fields that their default value is NULL, this is not necessarily true for PROTO SFNode fiels. So we have to take into account that any `DefaultValue` is possible. Note that this doesn't have to be `Nil`, but will be irrelevant if not DefaultValueExists. (Once I had an idea to automatically set `DefaultValue` to `Nil` when DefaultValueExists is set to `False`, but this was uncomfortable (like "what to do when `DefaultValue` is assigned non-nil when DefaultValueExists is false?").) Freeing of this is automatically managed, just like the normal Value property. This means that you can simply set `DefaultValue` to `Nil` or some existing node, and eventual memory deallocation of previous `DefaultValue` node (if unused) will happen automatically.
| `property DefaultValueExists: boolean read FDefaultValueExists write SetDefaultValueExists default false;`
| `property Value: TX3DNode read FValue write SetValue;`
| `property ParentNode: TX3DNode read FParentNode;`
VRML node containing this field. May be `Nil` if unknown, in special cases. Note that this property is exactly the same as TX3DFieldOrEvent.ParentNode, contains always the same value. But this is declared as TX3DNode, so it's more comfortable.
Generated by PasDoc 0.13.0 on 2013-08-17 21:27:15