OnAlarm(CallNumber as BSTR,They mean by this that LocationType is an array of VARIANTS (containing enumeration)
AlarmType as atAlarmType,
NumberOfLocations as long,
LocationIdentity(NumberOfLocations) as array of VARIANT containing BSTR,
LocationType(NumberOfLocations) as array of VARIANT containing atlocationType,
LocationTime(NumberOfLocations) as arrey of VARIANT containing BSTR)
When the OnAlarm Event is raised I have problems getting the 3 last values from it.
I have ported my application from VB.Net to C# and this is the only problem I can’t figure out how to solve in doing so.
In VB.Net it’s very easy to access these values as long as you don’t have the strong typing feature enabled. But not in C# where VARIANT type does not exist and is rather referenced as an object.
This is how OnAlarm looks in C#:
Expand|Select|Wrap|Line Numbers
- void OnAlarm(string CallNumber, ATOAC2Lib.atAlarmType AlarmType, int NumberOfLocations, ref object LocationIdentity, ref object LocationType, ref object LocationTime)
- Member of ATOAC2Lib._IatAlarm3Events
Expand|Select|Wrap|Line Numbers
- Private Sub atAlarm2_OnAlarm1(ByVal CallNumber As String, ByVal AlarmType As ATOAC2Lib.atAlarmType, ByVal NumberOfLocations As Integer, ByRef LocationIdentity As Object, ByRef LocationType As Object, ByRef LocationTime As Object) Handles atAlarm2.OnAlarm
- Dim ret, i As Integer
- Dim SecondLocationTime, FirstLocationTime, SecondLocation, FirstLocation, s As String
- Try
- If AlarmType <> ATOAC2Lib.atAlarmType.atAlarmType_Test Then
- FirstLocationTime = "0"
- SecondLocationTime = "0"
- SecondLocation = "0"
- FirstLocation = "0"
- For i = 0 To NumberOfLocations - 1
- If i = 0 Then
- If LocationType(i) = ATOAC2Lib.atLocationType.atLocationType_System900_Locator Then
- FirstLocation = HexToDec(LocationIdentity(i))
- FirstLocationTime = LocationTime(i)
- End If
- ElseIf i = 1 Then
- mylogfile.writelog(3, "AL2-" & LocationIdentity(i))
- If LocationType(i) = ATOAC2Lib.atLocationType.atLocationType_System900_Locator Then
- SecondLocation = HexToDec(LocationIdentity(i))
- SecondLocationTime = LocationTime(i)
- End If
- End If
- Next i
- Etc.
Expand|Select|Wrap|Line Numbers
- private void atAlarm2_OnAlarm1(string CallNumber, ATOAC2Lib.atAlarmType AlarmType, int NumberOfLocations, ref object LocationIdentity, ref object LocationType, ref object LocationTime)
- {
- int i;
- string SecondLocationTime;
- string FirstLocationTime;
- string SecondLocation;
- string FirstLocation;
- String[] tempLocationIdentity;
- ATOAC2Lib.atLocationType[] tempLocationType;
- String[] tempLocationTime;
- try
- {
- logger.Debug("Event atAlarm2_OnAlarm1 raised");
- tempLocationIdentity = (String[])LocationIdentity;
- tempLocationType = (ATOAC2Lib.atLocationType[])LocationType;
- tempLocationTime = (String[])LocationTime;
- if (AlarmType != ATOAC2Lib.atAlarmType.atAlarmType_Test)
- {
- FirstLocationTime = "0";
- SecondLocationTime = "0";
- SecondLocation = "0";
- FirstLocation = "0";
- AL_MsgCounter++;
- UpdateLabelText(this.LabelALCount, AL_MsgCounter.ToString());
- // Extract First/Second Location and First/Second Time
- for (i = 0; i <= NumberOfLocations - 1; i++)
- {
- if (i == 0)
- {
- logger.Debug("First alarm location at " + tempLocationIdentity[i]);
- //mylogfile.WriteLog(3, "AL1-" + tempLocationIdentity[i]);
- if (tempLocationType[i] == ATOAC2Lib.atLocationType.atLocationType_System900_Locator)
- {
- FirstLocation = HexToDec(tempLocationIdentity[i]);
- FirstLocationTime = tempLocationTime[i];
- }
- }
- else if (i == 1)
- {
- logger.Debug("Second alarm location at " + tempLocationIdentity[i]);
- //mylogfile.WriteLog(3, "AL2-" + tempLocationIdentity[i]);
- if (tempLocationType[i] == ATOAC2Lib.atLocationType.atLocationType_System900_Locator)
- {
- SecondLocation = HexToDec(tempLocationIdentity[i]);
- SecondLocationTime = tempLocationTime[i];
- }
- }
- }
- Etc.
System.InvalidCastException: Unable to cast object of type ‘System.Object[]’ to type ‘System.String[]’.Anyone that knows how to solve this?
I'm very thankful for all feedback.