This one has me baffled. I'm using RB2006 R4 on Mac OS 10.4 (I've also tried
R3) and am passing data as an array of structures to a method that walks the
array, extracts data from each structure and updates a REALSQLDatabase.
However, it doesn't work - some (but not all) of the data inserted into the
database are incorrect. I assumed that it was my error and spent a lot of time
studying my code to find the bug. Finally, I put some print statements into the
code to check the state of the data at key places. I've appended a section of
the method in question:
ListSize = UBound(TheList)
For i = 0 to ListSize
// Begin database transaction
TestDatabase.SQLExecute("BEGIN TRANSACTION")
dim TheMessage As string
TheMessage = "TheList: " _
+ str(TheList(i).InstrumentType.ID) + " " _
+ str(TheList(i).InstrumentType.SensorID) + " " _
+ str(TheList(i).InstrumentType.EngUnitID) + " " _
+ TheList(i).InstrumentType.Name
WinTest.EFieldTest.Text = WinTest.EFieldTest.Text + TheMessage + EndOfLine
CurrentElement = TheList(i)
TheMessage = "CurrentElement: " _
+ str(CurrentElement.InstrumentType.ID) + " " _
+ str(CurrentElement.InstrumentType.SensorID) + " " _
+ str(CurrentElement.InstrumentType.EngUnitID) + " " _
+ CurrentElement.InstrumentType.Name
WinTest.EFieldTest.Text = WinTest.EFieldTest.Text + TheMessage + EndOfLine
Select Case CurrentElement.Status
Case eChangeState.kNew
TestDatabase.SQLExecute("INSERT INTO InstrumentsTbl (TestID, SensorID,
EngUnitsID, InstrumentName)" _
+ "VALUES ('" + str(TestRef) + "','" +
str(CurrentElement.InstrumentType.SensorID) + "','" _
+ str(CurrentElement.InstrumentType.EngUnitID) + "','" +
CurrentElement.InstrumentType.Name + "')")
Case eChangeState.kDeleted
TestDatabase.SQLExecute("DELETE FROM InstrumentsTbl WHERE InstrumentID='" +
str(CurrentElement.InstrumentType.ID) + "'")
Case eChangeState.kModified
TestDatabase.SQLExecute("UPDATE InstrumentsTbl SET " _
+ "SensorID='" + str(CurrentElement.InstrumentType.SensorID) + "'," _
+ "InstrumentName='" + CurrentElement.InstrumentType.Name + "'," _
+ "EngUnitsID='" + str(CurrentElement.InstrumentType.EngUnitID) + "'" _
+ "WHERE InstrumentID='" + str(CurrentElement.InstrumentType.ID) + "'")
End
Next
TheList is the input array and CurrentElement is an instance of the custom
structure. Note the loops that write to a diagnostic window. The output was as
follows:
DlgConfigInstruments: -1 4 7 inst 1
DlgConfigInstruments: -1 5 8 inst 2
DlgConfigInstruments: -1 6 9 inst 3
TheList: -1 4 7 inst 1
CurrentElement: -1 0 0 inst 1 <== two values set to zero
TheList: -1 5 8 inst 2
CurrentElement: -1 0 0 inst 2 <== two values set to zero
TheList: -1 6 9 inst 3
CurrentElement: -1 6 9 inst 3 <== all values are OK
PrintRecords:
1 inst 1 0 0
2 inst 2 0 0
3 inst 3 6 9
"DlgConfigInstruments" shows the values that were put originally into the array
and passed to the data set method, "TheList" shows values received by the data
set method and "CurrrentElement" shows values in an individual structure
extracted from the array into a local variable. "PrintRecords" dumps the
database.
The data are correctly passed into the data set method but, when an element is
removed from the array and inspected, the data are (sometimes) corrupted. How
is this possible?
My workaround is to use the TheList(i) directly, rather than working with an
element removed from the list. I originally did the latter as an optimization -
I thought it would be better than referencing the array each time.
This looks like a bug in RB to me - an especially bad one in that it isn't
consistent. Any ideas?
--
John Hoover
[EMAIL PROTECTED]
301-890-6932 (H)
202-767-2335 (W)
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>