DBGrid and not-current record buffer access 
Author Message
 DBGrid and not-current record buffer access

Hi:

I'm trying to find a way to access all the records buffered by the
DataSet for a DBGrid in Delphi, in order to allow fly-over hints to work
properly with the grid.  In other words, if the mouse cursor is over a
grid cell that isn't on the current record, I'd like to be able to
correctly display additional information for that particular cell.

  From what I can tell looking at Borland's source for TCustomDBGrid,
during scroll operations the FDataLink references the buffered record
count in the DataSet, implying that the number of visible rows in the
grid is the number of records buffered in the DataSet.
In DBGrids.pas, the assignment to FDataLink is made in:
{{{{{{
procedure TCustomDBGrid.UpdateRowCount;
......
  FDataLink.BufferCount := VisibleRowCount;

Quote:
}}}}}}}

  The kludge that I've been using is to copy the records displayed in
the grid into an array, and reference this data for the hints.  However,
updating the array after a grid scroll is slow, and I've got a feeling
I'm missing an easier way to accomplish this.  I've tried using an
in-memory copy of the underlying table, which works, but can be a real
memory hog.  I've also tried using the table itself by decoupling the
link between the DataSet and the grid, and then going to the proper
record - but this gets complicated if an index is active, and results in
LOTs of hard drive activity.

Anybody know of a better way to do this?

Thanks for any suggestions!

(also posted to borland.public.delphi.database.desktop)



Wed, 18 Jun 1902 08:00:00 GMT  
 DBGrid and not-current record buffer access

Hi to all:
  I'm posting Jan's reply to my message here, in case it is of use to someone else.  I think his solution is a lot better than the one I was working on.

Hi Jan:
  Thanks very much for the quick reply; I had in the meantime found GetBuffer( ) and Buffers[ ] in TDataSet, and had been working on a solution involving exposing these in a descendant class, reading in the entire native record, and then converting field offsets to get the desired field value (I'm using TApolloDataSet with Clipper/DBase tables, which has a different record buffer format), but your solution is much simpler and more elegant (and more general, I think), in that one can still use TField to access the data.

Dave Wysocki
Unitech Research


Quote:


>>I'm trying to find a way to access all the records buffered by the
>>DataSet for a DBGrid in Delphi, in order to allow fly-over hints to work
>>properly with the grid. In other words, if the mouse cursor is over a
>>grid cell that isn't on the current record, I'd like to be able to
>>correctly display additional information for that particular cell.

>You can subclass the dataset descendant you're using (TTable/TQuery)
>in order to be able to access the Buffers[] property.  To get the
>value you want, you could temporarly copy the buffers contents to
>ActiveBuffer and restore ActiveBuffer afterwards.

>Another option is to change the value of FActiveRecord through the
>notorious hack of taking the pointer of the property (ActiveRecord in
>this case).  This would allow you to temporarily set the ActiveBuffer
>to another item of your Buffers[] array.

>Here's some code for the second option:

>  { Dirty Hack Alert ON }

>  TDataSetCracker = class(TDataSet)
>  public
>     property ActiveRecord;
>  end;

>  procedure TForm1.TestBuffer;
>  var
>     ActiveRecHack: PInteger;
>     OldActiveRec: Integer;
>  begin

>     // Save buffer index
>     OldActiveRec := ActiveRecHack^;
>     // Write to Table1.ActiveRecord
>     ActiveRecHack^ := 2;  // Just an arbitrary value
>     // Show value of another buffer
>     ShowMessage(Table1.Fields[0].AsString);
>     // Restore original buffer index
>     ActiveRecHack^ := OldActiveRec;
>  end;

>  { Dirty Hack Alert OFF }

>HTH,

>Jan



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. bookmark on prior record not current record.

2. Print records, not DBGrid

3. MS Access Counter fields and Insert (not DbGrid).

4. Accessing Specific Records in DBGrid

5. How to access other fields not on the current record?

6. DBGrid - How can I get number of Current/Selected Row

7. Ascertaining Current Row Number in a DBGrid ?

8. DBGrid - disallow changing current row

9. No Current Record with Filter in D2

10. How to get current record in a query

11. DBLookupComboBox: EDBEngineError 'No Current record'

12. Current Record Number

 

 
Powered by phpBB® Forum Software