Bill of Materials (HTreeEngine unit)

BOM data attached to nodes and the callbacks used by its visual control

ThBillOfMaterial

Optional BOM data owned by a ThTreeNode. The constructor receives the owning node. Operations that need a ThBOM_VisualTree delegate work to its published event handlers.
A node with BOM support holds catalog, quantity, dimensions, and dynamic fields. The ThTreeNode hierarchy supplies the parent-child relationships in a multilevel product structure.
ThBillOfMaterial = Class(TObject);

Create

Initializes BOM fields for Owner and assigns UniqueID from Server.NOW_UTC. In normal use ThTreeNode creates and owns this object when BOM support is enabled.
Constructor ThBillOfMaterial.Create(Owner: ThTreeNode);

ThtpKindType

Kind of a dynamic BOM field; the value controls formatting in Get_Dynamic_Fields_As_Memo.
ThtpKindType = (StringType, IntegerType, RealType, MoneyType, BoolType,
  DateType, DateTimeType, ProtoType, HourType);
In Get_Dynamic_Fields_As_Memo, StringType displays text; IntegerType, RealType, and MoneyType format numeric values.
BoolType displays localized Yes/No text. DateType, DateTimeType, and HourType format a date, date and time, or time as HH:NN.
ProtoType displays a prototype label supplied by BOM_Get_ValuesList when available; otherwise it displays the numeric index.

ThBillOfMaterial_Field

A dynamic field record. GetFieldObj returns a record value, rather than an object reference.
ThBillOfMaterial_Field = record
  Name, Visual_Name: String;
  Kind: ThtpKindType;
  Value: Variant;
  Readonly: Boolean;
  SelectFromMenuID: Integer;
end;
Name identifies a field for lookup and serialization; Visual_Name is its display label. Value stores the current value as a Variant.
Readonly makes the field read only when copied to a property grid. For a string field, SelectFromMenuID identifies choices supplied by BOM_Get_ValuesList.

Public fields

These are writable data fields, not calculated properties. Their effects depend on the application or attached visual tree.
DeclarationMeaning
ThBillOfMaterial.UniqueID: Double;
Numeric identifier used by Find_Node_By_UniqueID.
ThBillOfMaterial.Inserted_By_End_User: Boolean;
Marks a manually inserted node for selective child clearing.
ThBillOfMaterial.Catalogic_Number: String;
Catalog item number.
ThBillOfMaterial.Product_Name: String;
Product display name.
ThBillOfMaterial.Unit_Of_Measure: String;
Quantity unit.
ThBillOfMaterial.Quantity_Per_Parent: Double;
Quantity per parent item.
ThBillOfMaterial.TotalQuantity: Double;
Stored total quantity; this class does not calculate it.
ThBillOfMaterial.Width: Double;
Width in millimeters.
ThBillOfMaterial.Height: Double;
Height in millimeters.
ThBillOfMaterial.Depth: Double;
Depth in millimeters.
ThBillOfMaterial.Weight: Double;
Weight in kilograms.
ThBillOfMaterial.Integer_Unit_Quantity: Boolean;
Flag for whole-unit quantities; this class does not enforce rounding.
ThBillOfMaterial.Fix_Quantity: Boolean;
Fixed-quantity flag used by application logic.
ThBillOfMaterial.Tax_Free_Cost_Price: Double;
Cost excluding tax.
ThBillOfMaterial.Taxable_Cost_Price: Double;
Taxable cost field; interpretation belongs to the application.
ThBillOfMaterial.Cost_Currency: String;
Cost currency.
ThBillOfMaterial.Tax_Free_Selling_Price: Double;
Selling price excluding tax.
ThBillOfMaterial.Taxable_Selling_Price: Double;
Taxable selling price field.
ThBillOfMaterial.Selling_Currency: String;
Selling currency.
ThBillOfMaterial.Charge_For_Child_Nodes_Additions: Boolean;
Application pricing flag; Clear(True, ...) resets it to True.
ThBillOfMaterial.Warranty_Period_In_Months: Double;
Warranty period in months.
ThBillOfMaterial.Extra_Info: String;
Free text.
ThBillOfMaterial.Allow_To_Change_Width: String;
Application rule for width editing.
ThBillOfMaterial.Allow_To_Change_Height: String;
Application rule for height editing.
ThBillOfMaterial.Allow_To_Change_Depth: String;
Application rule for depth editing.
ThBillOfMaterial.Workflow_ID: Integer;
First workflow identifier.
ThBillOfMaterial.Workflow_ID_2: Integer;
Second workflow identifier.
ThBillOfMaterial.rt_Event_FieldModified: String;
Runtime event marker; Clear always empties it.

Clear

Always empties rt_Event_FieldModified. ProductInfo=True resets product fields but leaves UniqueID unchanged; DynamicFields=True removes all dynamic field records.
Procedure ThBillOfMaterial.Clear(ProductInfo, DynamicFields: Boolean);

Add_Child

Requires a nonempty catalog number, a visual BOM tree, and BOM_Add_Child handler. It creates a child node, sets its Extra_Info, and invokes the handler. The returned Boolean reflects an increased child count, not validation of the populated child.
Function ThBillOfMaterial.Add_Child(Catalogic_Number, Extra_Info: String;
  Quantity_PP, Width, Height, Depth: Double): Boolean;

Alert

Shows a popup with TextMessage and Catalogic_Number. Empty messages are ignored.
Procedure ThBillOfMaterial.Alert(TextMessage: String);

Run_Phantom

Calls the visual tree BOM_Run_Phantom handler for the owning node. Does nothing without a catalog number, visual BOM tree, or handler.
Procedure ThBillOfMaterial.Run_Phantom(Catalogic_Number: String);

FieldsCount

Returns the number of dynamic fields in _Fields; fixed public data fields are excluded.
Function ThBillOfMaterial.FieldsCount: Word;

GetFieldObj

Returns a copy of the zero-based dynamic field record. An invalid index produces an empty/default record.
Function ThBillOfMaterial.GetFieldObj(Index: Word): ThBillOfMaterial_Field;

GetFieldName

Returns the dynamic field internal name, or an empty string for an invalid index.
Function ThBillOfMaterial.GetFieldName(Index: Word): String;

GetFieldVisualName

Returns the dynamic field display name, or an empty string for an invalid index.
Function ThBillOfMaterial.GetFieldVisualName(Index: Word): String;

Get_Dynamic_Fields_As_Memo

Formats dynamic field labels and values with carriage-return separators. IncludeEmptyFields controls empty values; BoldValues wraps values in HTML b tags. ProtoType values may be resolved through BOM_Get_ValuesList with menu ID -100.
Function ThBillOfMaterial.Get_Dynamic_Fields_As_Memo(
  IncludeEmptyFields, BoldValues: Boolean): String;

AddField

Appends a dynamic field unless a case-insensitive name match already exists. If a visual tree supplies BOM_Init_Field_Value, that callback may change the initial value.
Procedure ThBillOfMaterial.AddField(Name, Visual_Name: String; Kind: ThtpKindType;
  Readonly: Boolean; InitValue: Variant; SelectFromMenuID: Integer);
if Root.BOM <> nil then
begin
  Root.BOM.AddField('Batch', 'Batch number', StringType, False, 'A-1', 0);
  Root.BOM.Field['Batch'] := 'A-2';
end;

RemoveField

Removes a dynamic field by case-insensitive internal name. Missing names have no effect.
Procedure ThBillOfMaterial.RemoveField(Name: String);

Add_Child_From_ProtoType

Creates a child and calls BOM_Add_ProtoChild when a visual tree and handler exist and Index is 0..128. The result indicates that the child count grew.
Function ThBillOfMaterial.Add_Child_From_ProtoType(Index: Word; Extra_Info: String;
  Quantity_PP, Width, Height, Depth: Double): Boolean;

Refresh

Calls BOM_Refresh_Node for the owner node if a visual BOM tree and handler are attached. The method does not calculate totals itself.
Procedure ThBillOfMaterial.Refresh;

String_Command

Passes the three strings to BOM_String_Command on the visual tree. An empty Command or missing handler has no effect; command meanings belong to the handler.
Procedure ThBillOfMaterial.String_Command(Command, PropName, AssignTo: String);

Find_Node_By_UniqueID

Checks the owning node, then searches descendants recursively by BOM.UniqueID. Returns nil when no match exists.
Function ThBillOfMaterial.Find_Node_By_UniqueID(FindID: Double): ThTreeNode;

Copy_To_PropGrid

Clears and populates a ThPropGrid with selected BOM data. FieldTypes is a combination of D (dynamic), M (measurements), W (weight), Q (quantity), and P (prices and flags); pass a ThPropGrid instance as the target.
Procedure ThBillOfMaterial.Copy_To_PropGrid(Target_HPropGrid: TSYE_Control; FieldTypes: String);
Root.BOM.Copy_To_PropGrid(PropGrid, 'DMWQ');

Field

Reads or writes a dynamic value by case-insensitive name. An unknown name reads as an empty string unless BOM_Get_Value_From_Header supplies a value; writing an unknown name has no effect.
Property ThBillOfMaterial.Field[Name: String]: Variant;