Subject Re: TIB_Cursor Education Needed
Author kumasoftllc
Thanks to all who responded. The underlying problem ended up being
the "AutoFetchAll" property that I had set TRUE. Doing so seems to
eliminate the ability to manually iterate throught the records.

--- In IBObjects@yahoogroups.com, "kumasoftllc" <kumasoftdev@b...>
wrote:
> I am attempting to use tib_cursor to populate the Items and
> ItemValues of a TIB_ComboBox. Using some sample code from one of
the
> Tech Info Sheets I tried the following in the FormCreate event:
>
> HMSDataModule.ReadOnlyTransaction.StartTransaction;
> cBox.Items.Clear;
> cBox.ItemValues.Clear;
> with myCursor do
> begin
> First;
> while not Eof do
> begin
> cBox.Items.Add(myCursor.FieldByName('myCode').AsString);
> cBox.ItemValues.Add(myCursor.FieldByName('myKey').AsString);
> Next;
> end;
> Close;
> end;
> HMSDataModule.ReadOnlyTransaction.Commit;
>
> The cursor was configured with both AutoFetchAll and AutoFetchFirst
> set to true, and retrieves 19 records.
>
> Oddly enough, this would NOT work as expected and the ComboBox
would
> always ended up empty. Debugging the code I discovered that Eof
was
> true on the first pass of the loop.
>
> Through some experimentation, I found that I COULD make this work
by
> using the TIB_Cursor AfterFetchRow event to perform the 2 cBox Add
> lines. So my FormCreate event now looked like the following:
>
> HMSDataModule.ReadOnlyTransaction.StartTransaction;
> cBox.Items.Clear;
> cBox.ItemValues.Clear;
> with myCursor do
> begin
> First;
> while not Eof do
> begin
> Next;
> end;
> Close;
> end;
> HMSDataModule.ReadOnlyTransaction.Commit;
>
> Through more experimentation if found that the loop was
unneccessary
> and the final code below would achieve the desired results.
>
> HMSDataModule.ReadOnlyTransaction.StartTransaction;
> cBox.Items.Clear;
> cBox.ItemValues.Clear;
> myCursor.First;
> myCursor.Close;
> HMSDataModule.ReadOnlyTransaction.Commit;
>
> Could someone please explain this confusing behavior to me, most
> importantly:
>
> 1. Why did the first snippet not work? It is nearly identical to
> sample code in the "Datasets Tech Info Sheet".
>
> 2. Why does the final form work even though I am no longer looping
> through the cursor? Is the "AutoFetchAll" causing this. Would it
> still work without the loop if I were to retrieve, say, 1000
> records? If the loop is not needed, what is the advantage to
> including it?
>
> Thanks.
>
> Bob