Discussion:
first and last row in a DBGrid
(too old to reply)
Stark
2010-02-08 15:55:40 UTC
Permalink
On the push of a button by the user, I would like to make changes to all of
the records of a dataset curenly visible on a DBGrid.
I need a way to identify the visible rows in order to apply a filter or run
a query on the dataset. How do I know the first and the last DBGrid rows ?
a***@aol.com
2010-02-08 16:20:57 UTC
Permalink
Post by Stark
On the push of a button by the user, I would like to make changes to all of
the records of a dataset curenly visible on a DBGrid.
I need a way to identify the visible rows in order to apply a filter or run
a query on the dataset. How do I know the first and the last DBGrid rows ?
From TDBGrid's ancestor . . .

TCustomGrid >> TDBGrid.TopRow
TCustomGrid >> TDBGrid.VisiblrRowCount

Alan Lloyd
Stark
2010-02-11 15:14:09 UTC
Permalink
I don't find these properties anywhere, Alan.
Can you be more explicit ? Thanks
Post by a***@aol.com
Post by Stark
On the push of a button by the user, I would like to make changes to all of
the records of a dataset curenly visible on a DBGrid.
I need a way to identify the visible rows in order to apply a filter or run
a query on the dataset. How do I know the first and the last DBGrid rows ?
From TDBGrid's ancestor . . .
TCustomGrid >> TDBGrid.TopRow
TCustomGrid >> TDBGrid.VisiblrRowCount
Alan Lloyd
a***@aol.com
2010-02-12 15:20:11 UTC
Permalink
Post by Stark
I don't find these properties anywhere, Alan.
Can you be more explicit ? Thanks
Look in Delphi Help for TDBGrid and Heirarchy. You will see that
TDBGrid is descended from TCustomDBGrid & TCustom Grid. Click on
TCustomGrid & then click on Properties in TCustomGrid. You will see
TopRow & VisibleRowCount in the list with (in D3) a yellow square
showing they are Protected properties.

Protected properties are not exposed (ie made available) except
explicitly by a descendant class _OR_ by typecasting to a new
descendant class. So you cannot (as you have found) access them as
properties of a TDBGrid.

But you can access them by declaring a descendant class of TDBGrid
(any name but I usually use a name meaningful for the purpose) :-

class
TDBGridRows = class(TDBGrid);

Then you can access the properties by :-

MyTopRow := TDBGridRows(TDBGrid).TopRow;
MyVisibleRows := TDBGridRows(TDBGrid).VisibleRowCount;

Protected & private properties are always there, but the compiler
prevents you accessing them unless you cheat <g>.

Alan Lloyd
Stark
2010-02-16 13:22:12 UTC
Permalink
Thanks a lot. You have the gift of concreteness and clarity.
Post by a***@aol.com
Post by Stark
I don't find these properties anywhere, Alan.
Can you be more explicit ? Thanks
Look in Delphi Help for TDBGrid and Heirarchy. You will see that
TDBGrid is descended from TCustomDBGrid & TCustom Grid. Click on
TCustomGrid & then click on Properties in TCustomGrid. You will see
TopRow & VisibleRowCount in the list with (in D3) a yellow square
showing they are Protected properties.
Protected properties are not exposed (ie made available) except
explicitly by a descendant class _OR_ by typecasting to a new
descendant class. So you cannot (as you have found) access them as
properties of a TDBGrid.
But you can access them by declaring a descendant class of TDBGrid
(any name but I usually use a name meaningful for the purpose) :-
class
TDBGridRows = class(TDBGrid);
Then you can access the properties by :-
MyTopRow := TDBGridRows(TDBGrid).TopRow;
MyVisibleRows := TDBGridRows(TDBGrid).VisibleRowCount;
Protected & private properties are always there, but the compiler
prevents you accessing them unless you cheat <g>.
Alan Lloyd
Loading...