OK, I think I might do this online since others may benefit from the discussion. Let's see how much I can help. I don't know all the details of your setup but that's OK. I can give you the general idea. With the holiday coming up and my work schedule I can't guarantee anything.
Let's start with the database first. I don't know how you connect your DB grid to you database but the ideas below can be adapted to whatever method you use, dataset, table, SQL, etc.
For each record in your table you want to find a corresponding tag in your string grid. (If you really wanted to, you could skip both the DB and string grid and read the table and file directly and only output the results.)
The example below is using a table instead of a dataset. If you are using SQL, the example will need to be changed slightly as will some of the called methods depending on whether you are using BDE, etc.
First loop through each record in the table. I do this in a try...catch statement in order to be a little safer on errors. If the table is not empty, get the first record. Go into a while loop checking for the end of the data in the table. Once you have a tag, we can get record(s) from the string grid in phase two.
Code:
try
{
if (MyOwnTable->IsEmpty()) // Nothing to get
{
// do something to inform the user
} // Nothing to get
// Set up temp variables
AnsiString TagStr, ValueStr;
// Get first record;
MyOwnTable->First();
// Now loop through all bundles
while (!MyOwnTable->Eof)
{
TagStr = MyOwnTable->FieldByName("Tag")->AsString;
ValueStr = MyOwnTable->FieldByName("Value")->AsString;
// Collect data from string grid in phase 2
// Next record
MyOwnTable->Next();
}
}
catch (...) // Opps
{
// Perform some sort of error cleanuo
// For example
MessageDlg("You have ... an ERROR!", mtError, TMsgDlgButtons() << mbOK, 0);
// and/or throw the error
throw;
} // Opps
You could also use a for loop instead of a while loop
Code:
for (MyOwnTable->First(); !MyOwnTable->Eof; MyOwnTable->Next())
{
...
}
Chew on this for a while and then we can move on to phase two.
James P. Cottingham
-----------------------------------------
I'm number 1,229!
I'm number 1,229!