Enquiring Mind
2008-06-04 10:17:42 UTC
Hi,
I have a method TTimeRecords.ReadFromDatabase(SQLConnection: TSQLConnection,
{..}) that reads data from an Interbase database into a TTimeRecords custom
object using a TSQLDataset component only. The SQLConnection parameter is a
SQLConnection that must be already open when the method is called. In the
calling procedure, I connect to the database, set the screen cursor to
crHourglass, call the ReadFromDatabase method, and finally reset the cursor
to crDefault and close the database connection. This is intended to display
an hourglass cursor while the potentially lengthy ReadFromDatabase procedure
is executing.
Now this approach sometimes doesn't work as intended, with the cursor
apparently changing back to the default value before the ReadFromDatabase
method execution has completed. In another NG someone suggested that this
may be due to some of the code between the cursor assignment statements
running in a different thread to the calling thread. If that's the case I
may need to call an OnTerminate event handler at an appropriate point in the
code to notify the calling thread that the asynchronous operation has
terminated. The problem is where? Can anyone advise whether the
TSQLConnection or TSQLDataset methods anywhere create new threads, and if
so, how I can assign an event handler to notify the main thread that the
operation has terminated? Alternatively, is there a way to force the
dbExpress methods to execute in the main program thread?
Thanks,
EM
I have a method TTimeRecords.ReadFromDatabase(SQLConnection: TSQLConnection,
{..}) that reads data from an Interbase database into a TTimeRecords custom
object using a TSQLDataset component only. The SQLConnection parameter is a
SQLConnection that must be already open when the method is called. In the
calling procedure, I connect to the database, set the screen cursor to
crHourglass, call the ReadFromDatabase method, and finally reset the cursor
to crDefault and close the database connection. This is intended to display
an hourglass cursor while the potentially lengthy ReadFromDatabase procedure
is executing.
Now this approach sometimes doesn't work as intended, with the cursor
apparently changing back to the default value before the ReadFromDatabase
method execution has completed. In another NG someone suggested that this
may be due to some of the code between the cursor assignment statements
running in a different thread to the calling thread. If that's the case I
may need to call an OnTerminate event handler at an appropriate point in the
code to notify the calling thread that the asynchronous operation has
terminated. The problem is where? Can anyone advise whether the
TSQLConnection or TSQLDataset methods anywhere create new threads, and if
so, how I can assign an event handler to notify the main thread that the
operation has terminated? Alternatively, is there a way to force the
dbExpress methods to execute in the main program thread?
Thanks,
EM