Once you have a function that implements your
custom column, you need to know when to update that column. The
most common method of doing this is to implement event handlers for
particular Process Analyst events. The example below uses the
PenCreated
event and the
HorizontalAxisChanged
event. These
events will verify that the column values will be updated when pens
are added to the display and when the time span changes.
See Also
IObjectViewItem.PutField [Method], IProcessAnalyst.BlockUpdates [Method], IProcessAnalyst.UnBlockUpdates [Method], PenCreated [Event], HorizontalAxisChanged [Event]
[VBA]
Sub UpdateMyColumn()
Dim iPaneItem As Integer
Dim iPane As Integer
Dim nPanes As Integer
Dim nSamples As Integer
Dim penItem As Object
Dim paneItem As Object
nSamples = test_CPA.NumberOfSamples
iPaneItem = 0
nPanes = test_CPA.Panes.Count
For iPane = 1 To nPanes
Dim pane As Object
Set pane = test_CPA.Panes.Item(iPane)
If IsNUll(pane) = False Then
Dim pen As Object
Dim iPen As Integer
Dim iPenItem As Integer
Dim nPens As Integer
iPaneItem = iPaneItem + 1
Set paneItem = test_CPA.ObjectView.Items.Item(iPaneItem)
test_CPA.BlockUpdates
iPenItem = 0
nPens = pane.Pens.Count
For iPen = 1 To nPens
Set pen = pane.pens.Item(iPen)
If IsNUll(pen) = False Then
Dim dDiff As Double
Dim sText As string
Dim dtStart As Date
Dim dtEnd As Date
Dim dtStartMs As Integer
Dim dtEndMs As Integer
iPenItem = iPenItem + 1
pen.GetHorizontalAxisTimeSpan dtStart, dtStartMs, dtEnd, dtEndMs,
False
dDiff = ((CDbl(dtEnd) - CDbl(dtStart)) / nSamples) * 86400
If (dDiff >= 0.001) Then
sText = CStr(Format(dDiff, "#0.000")) + " seconds"
Else
sText = "0.001 seconds"
End If
Set penItem = paneItem.Items.Item(iPenItem)
If IsNUll(penItem) = False Then
penItem.Putfield "DisplayPeriod", sText
End If
End If
Next
test_CPA.UnblockUpdates
End If
Next
End Sub
Sub CPA_E_HorizontalAxisChanged(hPen As Object)
UpdateMyColumn
End Sub
Sub CPA_E_PenCreated(hPen As Object)
UpdateMyColumn
End Sub
[Cicode]
FUNCTION UpdateMyColumn()
OBJECT hPA = ObjectByName("CPA");
OBJECT hPanes = _ObjectGetProperty(hPA, "Panes");
OBJECT hPane;
OBJECT hPens;
OBJECT hPen;
OBJECT hObjectView = _ObjectGetProperty(hPA, "ObjectView");
OBJECT hPaneItems = _OBJECTGetProperty(hObjectView, "Items");
OBJECT hPaneItem;
OBJECT hPenItems;
OBJECT hPenItem;
INT nPanes = _ObjectGetProperty(hPanes, "Count");
INT nPens;
INT iPen;
INT iPane = 0;
INT nSamples = _ObjectGetProperty(hPA, "NumberOfsamples");
INT iPenItem = 0;
INT iPaneItem = 0;
REAL dDiff;
REAL dtStart;
REAL dtEnd;
INT dtStartMs;
INT dtEndMs;
STRING sText;
FOR iPane = 1 TO nPanes DO
hPane = _ObjectCallMethod(hPanes, "get_Item", iPane);
IF ObjectIsValid(hPane) THEN
hPens = _ObjectGetProperty(hPane, "Pens");
nPens = _ObjectGetProperty(hPens, "Count");
iPaneItem = iPaneItem + 1;
_ObjectCallMethod(hPA, "BlockUpdates");
hPaneItem = _ObjectCallMethod(hPaneItems, "get_Item", iPaneItem);
iPenItem = 0;
FOR iPen = 1 TO nPens DO
hPen = _ObjectCallMethod(hPens, "get_Item", iPen);
IF ObjectIsValid(hPen) THEN
iPenItem = iPenItem + 1;
_ObjectCallMethod(hPen, "GetHorizontalAxisTimeSpan", dtStart,
dtStartMs, dtEnd, dtEndMs, 0);
dDiff = ((dtEnd - dtStart) / nSamples) * 86400;
IF dDiff > 0.001 THEN
sText = StrFormat(dDiff, 10, 3, "seconds");
ELSE
sText = "0.001 seconds"
END
hPenItems = _ObjectGetProperty(hPaneItem, "Items");
hPenItem = _ObjectCallMethod(hPenItems, "get_Item", iPenItem);
_ObjectCallMethod(hPenItem, "PutField", "DisplayPeriod", sText);
END
END
_ObjectCallMethod(hPA, "UnblockUpdates");
END
END
END
FUNCTION CPA_E_HorizontalAxisChanged(OBJECT hPA, OBJECT hPen)
UpdateMyColumn();
END
FUNCTION CPA_E_PenCreated(OBJECT hPA, OBJECT hPen)
UpdateMyColumn();
END