Class TMFNode

DescriptionHierarchyFieldsMethodsProperties

Unit

Declaration

type TMFNode = class(TX3DMultField)

Description

VRML/X3D field holding a list of nodes.

Just like SFNode, it's defined in this unit, as it uses TX3DNode. Note that items of MFNode cannot be nil (i.e. VRML/X3D doesn't allow to use NULL inside MFNode), contrary to SFNode.

Note that TMFNode implementation doesn't use TX3DSimpleMultField. One reason is that we don't want to parse MFNode items by SFNode parser, because MFNode doesn't allow NULL items. (In the past, another argument was that we want to use TX3DNodeList and it wasn't compatible with TX3DSimpleMultField. But now TX3DNodeList descends from TFPSList, so it isn't a problem.)

Just like for TSFNode: Note that we store AllowedChildren list, which is a list of classes allowed as Items. But this is used only to produce warnings for a user. You should never assert that every item actually is one the requested classes.

Hierarchy

Overview

Methods

Protected procedure SaveToStreamValue(Writer: TX3DWriter); override;
Protected function SaveToXmlValue: TSaveToXmlMethod; override;
Protected function GetCount: Integer; override;
Protected procedure SetCount(const Value: Integer); override;
Public constructor CreateUndefined(AParentNode: TX3DFileItem; const AName: string; const AExposed: boolean); override;
Public constructor Create(AParentNode: TX3DNode; const AName: string; const AAllowedChildrenClasses: array of TX3DNodeClass); overload;
Public constructor Create(AParentNode: TX3DNode; const AName: string; AAllowedChildrenClasses: TX3DNodeClassesList); overload;
Public constructor Create(AParentNode: TX3DNode; const AName: string; AnAllowedChildrenInterface: TGUID); overload;
Public destructor Destroy; override;
Public procedure Add(Node: TX3DNode); overload;
Public procedure Add(Position: Integer; Node: TX3DNode); overload;
Public procedure Delete(Index: Integer);
Public function Remove(const Node: TX3DNode): Integer;
Public function Extract(Index: Integer): TX3DNode;
Public procedure Clear;
Public procedure AssignItems(SourceItems: TX3DNodeList);
Public procedure Replace(Index: Integer; Node: TX3DNode);
Public procedure ParseValue(Lexer: TX3DLexer; Reader: TX3DReader); override;
Public procedure ParseXMLAttribute(const AttributeValue: string; Reader: TX3DReader); override;
Public procedure ParseXMLElement(Element: TDOMElement; Reader: TX3DReader); override;
Public function EqualsDefaultValue: boolean; override;
Public function Equals(SecondValue: TX3DField; const EqualityEpsilon: Double): boolean; override;
Public procedure Assign(Source: TPersistent); override;
Public procedure AssignValue(Source: TX3DField); override;
Public procedure AssignDefaultValueFromValue; override;
Public class function TypeName: string; override;
Public class function CreateEvent(const AParentNode: TX3DFileItem; const AName: string; const AInEvent: boolean): TX3DEvent; override;
Public procedure WarningIfChildNotAllowed(Child: TX3DNode);
Public function ChildAllowed(Child: TX3DNode): boolean;
Public procedure AssignDefaultItems(SourceItems: TX3DNodeList);
Public procedure ClearDefault;
Public procedure EnumerateValid(Func: TEnumerateChildrenFunction);

Properties

Public property Items: TX3DNodeList read FItems;
Public property ItemsArray[Index:Integer]: TX3DNode read GetItems;
Public property ParentNode: TX3DNode read FParentNode;
Public property DefaultItems: TX3DNodeList read FDefaultItems;
Public property DefaultValueExists: boolean read FDefaultValueExists write FDefaultValueExists default false;

Description

Methods

Protected procedure SaveToStreamValue(Writer: TX3DWriter); override;
 
Protected function SaveToXmlValue: TSaveToXmlMethod; override;
 
Protected function GetCount: Integer; override;

Get or set the number of items.

When increasing this, remember that new items of TMFNode will be Nil. You must immediately initialize them to something else then Nil by the Replace method. Other TMFNode methods, and outside code working with MFNodes, usually assumes that all MFNode children are non-nil. (As VRML/X3D spec don't really allow NULL items inside MFNode fields.)

Protected procedure SetCount(const Value: Integer); override;
 
Public 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.

Public constructor Create(AParentNode: TX3DNode; const AName: string; const AAllowedChildrenClasses: array of TX3DNodeClass); overload;
 
Public constructor Create(AParentNode: TX3DNode; const AName: string; AAllowedChildrenClasses: TX3DNodeClassesList); overload;

Constructor that takes a list of allowed children classes. Note that we copy the contents of AAllowedChildrenClasses, not the reference.

Public constructor Create(AParentNode: TX3DNode; const AName: string; AnAllowedChildrenInterface: TGUID); overload;

Constructor that allows as children any implementor of given interface.

Public destructor Destroy; override;
 
Public procedure Add(Node: TX3DNode); overload;
 
Public procedure Add(Position: Integer; Node: TX3DNode); overload;
 
Public procedure Delete(Index: Integer);
 
Public function Remove(const Node: TX3DNode): Integer;

Search list for given node, and, if found, remove it. Returns the index of removed item, or -1 if not found.

Public function Extract(Index: Integer): TX3DNode;

Remove child with given Index, and return it, never freeing it. This is analogous to TX3DNode.ExtractChild, see there for more explanation.

Public procedure Clear;
 
Public procedure AssignItems(SourceItems: TX3DNodeList);
 
Public procedure Replace(Index: Integer; Node: TX3DNode);
 
Public procedure ParseValue(Lexer: TX3DLexer; Reader: TX3DReader); override;
 
Public procedure ParseXMLAttribute(const AttributeValue: string; Reader: TX3DReader); override;
 
Public procedure ParseXMLElement(Element: TDOMElement; Reader: TX3DReader); override;
 
Public function EqualsDefaultValue: boolean; override;
 
Public function Equals(SecondValue: TX3DField; const EqualityEpsilon: Double): boolean; override;
 
Public procedure Assign(Source: TPersistent); override;
 
Public procedure AssignValue(Source: TX3DField); override;
 
Public procedure AssignDefaultValueFromValue; override;
 
Public class function TypeName: string; override;
 
Public class function CreateEvent(const AParentNode: TX3DFileItem; const AName: string; const AInEvent: boolean): TX3DEvent; override;
 
Public procedure WarningIfChildNotAllowed(Child: TX3DNode);

Checks is Child allowed on the list of nodes of this MFNode, 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 added to this node. In other words, you should only pass as Child a node that you want to add (e.g. by Add) to this field, otherwise OnWarning message will be a little unsensible.

Public function ChildAllowed(Child: TX3DNode): boolean;
 
Public procedure AssignDefaultItems(SourceItems: TX3DNodeList);

Operate on DefaultItems, just like analogous AssignItems and Clear.

Public procedure ClearDefault;
 
Public procedure EnumerateValid(Func: TEnumerateChildrenFunction);

Calls Func for all current children that are valid (allowed by ChildAllowed).

The main use for this is to simplify implementation of TX3DNode.DirectEnumerateActive overrides in TX3DNode descendants.

Properties

Public property Items: TX3DNodeList read FItems;

Lists items of this field.

Do not modify this list explicitly. Use only methods in this class like Add. They take care of calling appropriate AddParentField / RemoveParentField, otherwise you could break reference-counting of nodes by ParentFields.

Public property ItemsArray[Index:Integer]: TX3DNode read GetItems;
 
Public property ParentNode: TX3DNode read FParentNode;
 
Public property DefaultItems: TX3DNodeList read FDefaultItems;

Lists default items of this field.

Do not modify this list explicitly. Use only methods in this class like AssignDefaultItems (they take care of calling appropriate AddParentField / RemoveParentField, otherwise you could break reference-counting of nodes by ParentFields).

Public property DefaultValueExists: boolean read FDefaultValueExists write FDefaultValueExists default false;