How to stop fetching records in TOracleDataSet?

Daniel Stoch

Member²
Hi,

I want to allow user to stop fetching records in TOracleDataSet. There is a very good example about activating dataset in a thread, but the problem is when user wants to scroll data in active dataset?

I have the following situation, eg.:
- OracleDataSet.Active := True -> fetching first 100 records, user can browse them in a grid,
- OracleDataSet.Last -> user scrolls to the last record (or any other record which is not fetched yet), OracleDataSet fires QueryRecord procedure to fetch next records,
- how to stop this operation?

I can write a "monitor" thread: when user press ESC button I set up a flag to stop fetching records, which will be examinated in AfterFetchRecord event. But I don't know when should I start and when should I stop this thread :( . I think events like: BeforeFetching and AfterFetching will be useful. But unfortunatelly TOracleDataSet does not have such events, BeforeQuery and AfterQuery are called in diffrent situations (before activating and after fetching last record).

Have you any suggestions how to solve this problem?

Best regards,
Daniel Stoch
 
You can use the AfterFetchRecord event handler to stop the operation. The documentation contains an example that asks the user if he wants to continue after fetching 1000 records.
 
I think you don't understand me ;) . I know that I can use the AfterFetchRecord event handler to stop the operation, by asking the user if he wants to continue after fetching N (eg. N = 1000) records. I have such functionality already implemented.

But users are very unsatisfied that they must click "Yes", "Yes", "Yes" so many times, after fetching every N records. Users may want to fetch all other records without prompting every N records, but with option to pause query in any moment. I cannot tell my clients: "It is impossible because of components for accessing Oracle we are using". I think it is possible, but I need something like BeforeFetching and AfterFetching events.

Another problem is when application hangs before fetching next N records. How to abort fetching then? This is because I wrote about "monitor" thread to stop fetching next records. So it is not such easy problem as you think :) .

Greetings,
Daniel Stoch
 
Originally posted by Daniel Stoch:
[QB] So it is not such easy problem as you think :) .

Really the problem is as easy as Marco think and you will recognize it if you would think a little. The sample referred by Marco shows you how to stop fetch, but yhis is only a sample - you need not to make exact calc of it. Just put in the user interface some element (button menu item or something) which set some internal flag when clicked. Then check this flag in AfterFetchRecord event. In worst case you will have one additional record, normally, no big deal. :eek:
 
Really the problem is not as easy as you al0 think and you will recognize it if you would think a little :p .


Just put in the user interface some element (button menu item or something) which set some internal flag when clicked. Then check this flag in AfterFetchRecord event.
Have you read my first message carefully? I write about the same solution. But...
We have one thread in our VCL application. User scrolls to the last record then application hangs until this last record will be fetched, because of internal loop inside TOracleDataSet. How user can click anything while any windows message is not processed until TOracleDataSet stop fetching records? The second thread is necessary. My main problem is when to suspend that thread, because there is no information or event when TOracleDataSet stops fetching records. Thats all.

Yes, think a while before posting your great solutions :eek: .

Best regards,
Daniel Stoch
 
Back
Top