# Results

The Results object provides access to the Results page in the Scripting window. This page is typically used to track the values of element properties, but can be extended to include user-defined fields as well. The Results object is used to dynamically add new result fields, update the contents of existing fields (which have been defined by the Results | Configure… menu item), load and save results to a file, and chart flow paths through nodes in the network.
Function/Property | Description
Add(Name: String; ShowOnGraph: Boolean; Color: Integer; GraphTitle, XAxisLabel, YAxisLabel: String): Integer | Add a new Result field (column) to the Results table. This function returns the FieldNo of the newly added Result field, or -1 if the field already exists.
ChartFlowPath(PathTypes: Set; StartNode, EndNode, PressureHeadUnitId: Integer): Integer | Chart the "profile" of pressure along a particular flowpath (from StartNode to EndNode). The type of profile is determined by the value of PathTypes, and the resulting values will be displayed in PressureHeadUnitId. See Plotting Flow Paths.
Clear | Clear all Result data values.
DataCount: Integer | Get the number of Result data values (i.e, the number of rows in the Results table).
Delete(NameOrFieldNo: String): Boolean | Delete the Result field specified by NameOrFieldNo. This function will return True if the field was deleted; and False if the field does not exist.
DeleteFields | Delete all Result fields & data values – this will delete all columns and rows in the Results table.
FieldCount: Integer | Get the number of Result fields (i.e., Result table columns).
FieldName(FieldNo: Integer): String | Get a Result field's name. FieldNo refers to the Result table column number you wish to access.
Get(NameOrFieldNo: Variant; RowNo: Integer): Float | Get the value of a Result field (specified by NameOrFieldNo) for a given row number.
Load(Filename: String): Boolean | Load the Results from a file. Returns True if the file exists and could be loaded.
Refresh | Update the Results table and charts.
Save(Filename: String): Boolean | Save the Results to a file. Returns True if the file is created.
SaveToXLS(Filename: String): Boolean | Save the Results to an XLS file. Returns True if the file is created.
SaveToXML(Filename: String): Boolean | Save the Results to an XML file. Returns True if the file is created.
Set(NameOrFieldNo: Variant; RowNo: Integer; Value: Float) | Set the value of a Result field (specified by NameOrFieldNo) for a given row number.
Update(NewRowId: Integer): Integer | Add a new Result data row, setting the values of all fields to the element property values they are associated with in the Network.
Updating Result Values The Update function is used to add a new data row to the Results table, setting the values of all fields to the element property values they are associated with in the Network. The function returns the index of the newly added row. ▪Update(NewRowId: Integer=0): Integer You can use the optional NewRowId parameter to specify the identifier of the row. This value will be displayed in the '#' column of the Results table, and will be the x-axis value for all Results fields that are displayed in charts. If you do not include a value for NewRowId, the current number of rows + 1 is used. Example: begin // Clear all existing results field data. Results.Clear; // Assuming that you've used the Results | Configures Results... menu item to track Temperature for i := 1 to 5 do begin Pressure := Network.Get(1, 'BoundaryPressure'); Network.Set(1, 'BoundaryPressure', Pressure + 1.5); Network.Calculate; Results.Update(i); end; end; Note: Update will not update any user-defined Result fields. You must use the Set routine to do this. Getting and Setting Result Field Values The Results object provides two methods to get and set Result field values: ▪Get(NameOrFieldNo: Variant; RowNo: Integer): Float ▪Set(NameOrFieldNo: Variant; RowNo: Integer; Value: Float) Example: Add a new result field – 'TestField' – and update it on each iteration of the loop. uses Graphics; // Include this to get access to clGreen begin // Clear all existing results field data. Results.Clear; // Add a new field – Q – to be shown on the graph in green. // Note: Q is not tied to any particular element in the network. TestColumnId := Results.Add('Test', True, clGreen, 'for loop', '', 'i value'); for i := 0 to 4 do Results.Set(TestColumnId, i, i * 5); Output.Clear; for i := 0 to 4 do Output.Add(Results.Get(TestColumnId, i)); end; Note: FieldNo and RowNo are 0-based, i.e., the first field number in the Results is 0, and the first RowNo in the Results is 0. Adding New Result Fields The Add function is available to allow the creation of user-defined Result fields at 'run-time'. At design-time use the Results | Configure… menu item to add the properties of nodes and pipes that you want to store results for. ▪Add(Name: String; ShowOnGraph: Boolean; Color: Integer; GraphTitle, XAxisLabel, YAxisLabel: String): Integer The new Result field's properties are specified by Add's parameters: ▪Name – The name of the new Result field. This will be displayed in the Results table column header. The Name should be unique, otherwise, a new Result field will not be created. ▪ShowOnGraph – Set to True if you want the Result field to be displayed in a graph on the Results page. ▪Color – Use the constant values from the Graphics library to specify the color you want the graph to be drawn in. See Graphics Color Constants for a full list. ▪GraphTitle – This is an optional parameter you can use to specify a title that will appear at the top of the graph. ▪XAxisLabel – This is an optional parameter you can use to specify the X-axis label. ▪YAxisLabel – This is an optional parameter you can use to specify the Y-axis label. This function returns the FieldNo of the newly added Result field, or -1 if the field already exists. Note that FieldNo will be 0-based, i.e., the first field number will be 0. Example: Add a new result field – 'Q' – and update it on each iteration of the loop. uses Graphics; // Include this to get access to clGreen begin // Clear all existing results field data. Results.Clear; // Add a new field – Q – to be shown on the graph in green. // Note: Q is not tied to any particular element in the network. FlowColumnId := Results.Add('Q', True, clGreen, 'Q Test', '', 'Q'); Node1 := Network.GetElement(1); for i := 1 to 5 do begin ePressure := Node1.Property['BoundaryPressure']; // Could use Node1.Get(66); Node1.Property['BoundaryPressure'] := ePressure + 1.5; Network.Calculate; // Update all the fields in the Results with their current // network element values. Update will return the index of the // row updated. NextRowIndex := Results.Update; // Set the value of Q to Node1's Flow value. Results.Set(FlowColumnId, NextRowIndex, Node1.Property['InternalFlow']); // Internal Flow = Property Id 46 end; Network.Refresh; // Update the Results Table and Charts. Results.Refresh; end; Plotting Flow Paths The ChartFlowPath function is used to chart the "profile" of pressure along specified flow paths (from StartNode to EndNode). The type of profile is determined by the value of PathTypes, and the resulting values will be displayed in PressureHeadUnitId. ▪ChartFlowPath(PathTypes: Set; StartNode, EndNode, PressureHeadUnitId: Integer): Integer The values for the PathTypes set are:
Path Type | Id | Constant
Hydraulic Grade Line | 0 | cfpHGL
Energy Grade Line | 1 | cfpEGL
Stagnation Pressure | 2 | cfpStagnationPressure
Static Pressure | 3 | cfpStaticPressure
You must use the SetOf() routine to specify what you want to chart. If you want to use the cfp constants you must include FFConstants in the uses clause. Example: This script will Plot the Hydraulic Grade Line (HGL) and Energy Grade Line (EGL) from Nodes 1 to 23. It will automatically add two Result Fields - HGL_1 and EGL_1 - and populate them with the values from Nodes 1 to 23 (including the Pipes in-between). uses FFConstants; // Include to get access to ChartFlowPath constants. begin // Clear the existing result values. Results.Clear; Network.Calculate; // Chart the HGL and EGL paths from nodes 1 to 23 Results.ChartFlowPath(SetOf([cfpHGL, cfpEGL]), 1, 23, 1208); // 1208 = psi g // The above could be written as: Results.ChartFlowPath(SetOf([0, 1]), 1, 23, 1208); end;