Two read-only, runtime properties, Eof (End-of-file) and Bof(Beginning-of-file), are useful when you want to iterate through all records in a dataset.
When EOF is True, it indicates that the cursor is unequivocally at the last row in a dataset. Eof is set to True when an application
Eof is commonly tested in a loop condition to control iterative processing of all records in a dataset. If you open a dataset containing records (or you call First) Eof is False. To iterate through the dataset a record at a time, create a loop that steps through each record by calling Next, and terminates when Eof is True. Eof remains False until you call Next when the cursor is already on the last record.
The following code illustrates one way you might code a record-processing loop for a dataset called CustTable:
CustTable.DisableControls; try CustTable.First; { Go to first record, which sets Eof False } while not CustTable.Eof do { Cycle until Eof is True } begin { Process each record here } . . . CustTable.Next; { Eof False on success; Eof True when Next fails on last record } end; finally CustTable.EnableControls; end;
CustTable->DisableControls(); // Speed up processing; prevent screen flicker try { while (!CustTable->Bof) // Cycle until Bof is true ( // Process each record here . . . CustTable->Prior(); // Bof false on success; Bof true when Prior fails on first record } } __finally { CustTable->EnableControls(); }
CustTable->DisableControls(); try { for (CustTable->First(); !CustTable->Eof; CustTable->Next()) ( // Process each record here . . . } } __finally { CustTable->EnableControls(); }
When BOF is True, it indicates that the cursor is unequivocally at the first row in a dataset. Bof is set to True when an application
Like EOF, Bof can be in a loop condition to control iterative processing of records in a dataset. The following code illustrates one way you might code a record-processing loop for a dataset called CustTable:
CustTable.DisableControls; { Speed up processing; prevent screen flicker } try while not CustTable.Bof do { Cycle until Bof is True } begin { Process each record here } . . . CustTable.Prior; { Bof False on success; Bof True when Prior fails on first record } end; finally CustTable.EnableControls; { Display new current row in controls } end;
Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
|
What do you think about this topic? Send feedback!
|