Board index » delphi » How to get current record in a query

How to get current record in a query

I have a DBGrid that contains the results of a SQL query.  Can anyone tell
me how I can tell what the selected record number is?  I am trying to
display a message to the user saying: "Record # x of xxx".  I am using
RecordCount to get the "of xxx" part, and just need the first part to
complete it.

Thanks for the assistance.

D. Hayden

 

Re:How to get current record in a query


In article <01bb9a88$b5f71800$9f0b25a6@csp0155a>, Daniel Hayden
<Daniel.Hay...@mci.com> writes

Quote
>I have a DBGrid that contains the results of a SQL query.  Can anyone tell
>me how I can tell what the selected record number is?  I am trying to
>display a message to the user saying: "Record # x of xxx".  I am using
>RecordCount to get the "of xxx" part, and just need the first part to
>complete it.

Define a global variable HitNumber, initialise it to 1 and then
increment/decrement it in the OnClick event of a TDBNavigator. Something
like;

if Button = nbFirst then         {Move to first record in Query1}
    HitNumber := 1;
if Button = nbLast then          {Move to last record in Query1}
    HitNumber := Query1.RecordCount;
if Button = nbNext then          {Move to next record in Query1}
    Inc(HitNumber);
if Button = nbPrior then         {Move to previous record in Query1}
    Dec(HitNumber);
{Ensure that record at cursor is in range of all hits found}
if HitNumber < 1 then
    HitNumber := 1;
if HitNumber > Query1.RecordCount then
    HitNumber := Query1.RecordCount;
{Construct and display total number of results and position of cursor in
them}
Label1.Caption := IntToStr(HitNumber) + ' of ' +
IntToStr(Query1.RecordCount);
--
Barney Tyrwhitt-Drake

Re:How to get current record in a query


Quote
Daniel Hayden wrote:

> I have a DBGrid that contains the results of a SQL query.  Can anyone tell
> me how I can tell what the selected record number is?  I am trying to
> display a message to the user saying: "Record # x of xxx".  I am using
> RecordCount to get the "of xxx" part, and just need the first part to
> complete it.

> Thanks for the assistance.

> D. Hayden

Visit Delphi Super Page ( http://www.cdrom.com/pub/delphi_www/ ) and
get zip file dbpos.zip (Delphi 1.0 - freeware - Database).

There is what you want.

BYE.
-- /*\*/*\*/*\*/*\*/*\*/*\*/*\*/*\*/*\*/*\*/*\*/*\*/*\*/*\*/*\*/*\*
Vladimir Zderic B.E.E.      mailto:vladimir.zde...@ci.tel.hr
Consult Invest              http://www.open.hr/com/ci/index.html
/*\*/*\*/*\*/*\*/*\*/*\*/*\*/*\*/*\*/*\*/*\*/*\*/*\*/*\*/*\*/*\*

Other Threads