|
| 1 | +# TBoldElement |
| 2 | + |
| 3 | +`TBoldElement` is the abstract base class for all elements in the Bold framework. It provides common functionality for string representation, comparison, assignment, and subscription. |
| 4 | + |
| 5 | +## Class Definition |
| 6 | + |
| 7 | +```pascal |
| 8 | +TBoldElement = class(TBoldSubscribableObject) |
| 9 | +public |
| 10 | + // String representation |
| 11 | + property AsString: string; |
| 12 | + property DisplayName: string; |
| 13 | + function GetStringRepresentation(Representation: TBoldRepresentation): string; |
| 14 | + procedure SetStringRepresentation(Representation: TBoldRepresentation; const Value: string); |
| 15 | +
|
| 16 | + // Comparison |
| 17 | + function CompareTo(BoldElement: TBoldElement): Integer; |
| 18 | + function IsEqual(BoldElement: TBoldElement): Boolean; |
| 19 | +
|
| 20 | + // Assignment |
| 21 | + procedure Assign(Source: TBoldElement); |
| 22 | + function IsEqualAs(CompareType: TBoldCompareType; BoldElement: TBoldElement): Boolean; |
| 23 | +
|
| 24 | + // OCL evaluation |
| 25 | + function EvaluateExpression(const Expression: string): TBoldElement; |
| 26 | + function EvaluateExpressionAsNewElement(const Expression: string): TBoldElement; |
| 27 | +
|
| 28 | + // Mutability |
| 29 | + property Mutable: Boolean; |
| 30 | +end; |
| 31 | +``` |
| 32 | + |
| 33 | +## Inheritance |
| 34 | + |
| 35 | +```mermaid |
| 36 | +classDiagram |
| 37 | + TBoldSubscribableObject <|-- TBoldElement |
| 38 | + TBoldElement <|-- TBoldDomainElement |
| 39 | + TBoldElement <|-- TBoldSystem |
| 40 | +
|
| 41 | + TBoldElement : +AsString |
| 42 | + TBoldElement : +CompareTo() |
| 43 | + TBoldElement : +EvaluateExpression() |
| 44 | +
|
| 45 | + click TBoldSystem href "TBoldSystem.md" "TBoldSystem documentation" |
| 46 | +``` |
| 47 | + |
| 48 | +## Properties |
| 49 | + |
| 50 | +### AsString |
| 51 | + |
| 52 | +Universal string representation: |
| 53 | + |
| 54 | +```pascal |
| 55 | +var |
| 56 | + Element: TBoldElement; |
| 57 | +begin |
| 58 | + ShowMessage(Element.AsString); |
| 59 | +end; |
| 60 | +``` |
| 61 | + |
| 62 | +### DisplayName |
| 63 | + |
| 64 | +Human-readable name for display purposes: |
| 65 | + |
| 66 | +```pascal |
| 67 | +ShowMessage('Working with: ' + Element.DisplayName); |
| 68 | +``` |
| 69 | + |
| 70 | +### Mutable |
| 71 | + |
| 72 | +Indicates whether the element can be modified: |
| 73 | + |
| 74 | +```pascal |
| 75 | +if Element.Mutable then |
| 76 | + Element.AsString := 'New Value'; |
| 77 | +``` |
| 78 | + |
| 79 | +## Methods |
| 80 | + |
| 81 | +### CompareTo |
| 82 | + |
| 83 | +Compare two elements: |
| 84 | + |
| 85 | +```pascal |
| 86 | +var |
| 87 | + Result: Integer; |
| 88 | +begin |
| 89 | + Result := Element1.CompareTo(Element2); |
| 90 | + // Result < 0: Element1 < Element2 |
| 91 | + // Result = 0: Element1 = Element2 |
| 92 | + // Result > 0: Element1 > Element2 |
| 93 | +end; |
| 94 | +``` |
| 95 | + |
| 96 | +### IsEqual |
| 97 | + |
| 98 | +Check equality: |
| 99 | + |
| 100 | +```pascal |
| 101 | +if Element1.IsEqual(Element2) then |
| 102 | + ShowMessage('Elements are equal'); |
| 103 | +``` |
| 104 | + |
| 105 | +### Assign |
| 106 | + |
| 107 | +Copy value from another element: |
| 108 | + |
| 109 | +```pascal |
| 110 | +TargetElement.Assign(SourceElement); |
| 111 | +``` |
| 112 | + |
| 113 | +### EvaluateExpression |
| 114 | + |
| 115 | +Evaluate an OCL expression with this element as context: |
| 116 | + |
| 117 | +```pascal |
| 118 | +var |
| 119 | + Customer: TBoldObject; |
| 120 | + OrderCount: TBoldElement; |
| 121 | +begin |
| 122 | + OrderCount := Customer.EvaluateExpression('self.orders->size'); |
| 123 | + ShowMessage('Orders: ' + OrderCount.AsString); |
| 124 | +end; |
| 125 | +``` |
| 126 | + |
| 127 | +### EvaluateExpressionAsNewElement |
| 128 | + |
| 129 | +Evaluate and return a new element (caller owns it): |
| 130 | + |
| 131 | +```pascal |
| 132 | +var |
| 133 | + Customer: TBoldObject; |
| 134 | + ActiveOrders: TBoldObjectList; |
| 135 | +begin |
| 136 | + ActiveOrders := Customer.EvaluateExpressionAsNewElement( |
| 137 | + 'self.orders->select(status = ''Active'')' |
| 138 | + ) as TBoldObjectList; |
| 139 | + try |
| 140 | + // Use ActiveOrders |
| 141 | + finally |
| 142 | + ActiveOrders.Free; |
| 143 | + end; |
| 144 | +end; |
| 145 | +``` |
| 146 | + |
| 147 | +## String Representations |
| 148 | + |
| 149 | +Bold supports multiple string representations for different purposes: |
| 150 | + |
| 151 | +| Representation | Constant | Purpose | |
| 152 | +|----------------|----------|---------| |
| 153 | +| Default | `brDefault` | General display | |
| 154 | +| Short | `brShort` | Compact display | |
| 155 | +| Long | `brLong` | Detailed display | |
| 156 | + |
| 157 | +```pascal |
| 158 | +// Get specific representation |
| 159 | +var |
| 160 | + ShortName: string; |
| 161 | +begin |
| 162 | + ShortName := Element.GetStringRepresentation(brShort); |
| 163 | +end; |
| 164 | +``` |
| 165 | + |
| 166 | +## Derived Classes |
| 167 | + |
| 168 | +| Class | Description | |
| 169 | +|-------|-------------| |
| 170 | +| [TBoldSystem](TBoldSystem.md) | The Object Space manager | |
| 171 | +| TBoldDomainElement | Base for objects and members | |
| 172 | +| [TBoldObject](TBoldObject.md) | Domain object instances | |
| 173 | +| [TBoldMember](TBoldMember.md) | Attributes and references | |
| 174 | +| [TBoldAttribute](TBoldAttribute.md) | Simple values | |
| 175 | +| [TBoldObjectList](TBoldObjectList.md) | Collections | |
| 176 | + |
| 177 | +## See Also |
| 178 | + |
| 179 | +- [TBoldSystem](TBoldSystem.md) - Object Space manager |
| 180 | +- [TBoldObject](TBoldObject.md) - Domain objects |
| 181 | +- [Subscriptions](../concepts/subscriptions.md) - Change notification |
0 commit comments