Solved

successive table record count problems

Posted on 1998-05-26
17
223 Views
Last Modified: 2011-10-03
I present a list of databases to the user, as they scroll through them I show among other things the record count. Each time I reset the databasename and tablename for the table and call the function TableCount as follows:

label1.Caption := IntToStr(TableCount(table1.DBHandle));

where

function TableCount(hDb: hDBIDb): longint;
{to use the function, pass in either TDatabase.handle or
 TTable.DBHandle. The TDatabase or TTable must be open in both cases}
var
   hCur: hDBICur;
begin
   Result := 0;
   Check(DbiOpenTableList(hDb,FALSE, FALSE, '*.*', hCur));
   try
      Check(DbiGetRecordCount(hCur, Result));
   finally
      Check(DbiCloseCursor(hCur));
   end;
end;

The problem is that the record count does not update after the first time, it returns the same number of records everytime. Any ideas?

Thanks, Tom.
0
Comment
Question by:tomcorcoran
  • 7
  • 6
  • 2
  • +2
17 Comments
 
LVL 2

Expert Comment

by:kjteng
ID: 1347945
did u set any range limit?
why don't u use the recordcount property?
0
 

Author Comment

by:tomcorcoran
ID: 1347946
I only do what I show. I was lead to understand that there was more overhead using recordcount. For example it's more efficient to check if both BOF and EOF are True to see if a table is empty than checking recordcount is zero. Tom.
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1347947
is the line Check(DbiCloseCursor(hCur)) always executed after the first try?
0
 

Author Comment

by:tomcorcoran
ID: 1347948
Yes, every time a new database is selected I do
label1.Caption := IntToStr(TableCount(table1.DBHandle));

0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1347949
So table1.Dbhandle changes from table to table? Or not? If Table1 stays table1 it's normal you don't see any change in the record count when you just browse through the table. Record count just gives the total of records.
0
 
LVL 5

Expert Comment

by:ronit051397
ID: 1347950
I think you should pass the table Handle and not the Table DBHandle.
In this case you will get a compilation error because DbiOpenTableList takes a DBHandle but DbiGetRecordCount takes a handle, so I don't know how you find the Handle out of the DBHandle.
0
 

Author Comment

by:tomcorcoran
ID: 1347951
DBHandle does change I checked that....go figure. Interesting Ronit.
0
 
LVL 3

Expert Comment

by:rickpet
ID: 1347952
Ronit...your on the right path...

   Check(DbiOpenTableList(hDb,FALSE, FALSE, '*.*', hCur));

This bde call returns the cursor to a table of all tables in the Database...in hCur
So you should always get the same value...the total number of tables

Change it to something like...

function TableCount(Value: TTable): longint;
{to use the function, pass in  TTable}
var
   hCur: hDBICur;
begin
   Result := 0;
   Check(dbiGetCursorForTable(Value.DbHandle, pchar(Value), nil, hCur));
   try
      Check(DbiGetRecordCount(hCur, Result));
   finally
      Check(DbiCloseCursor(hCur));
   end;
end;

Rick
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:tomcorcoran
ID: 1347953
Rick,

Thanks for the respose. I tried your implementation, passing in ttable (tablename and databasename set, active is True) I get the error - unable to open object on the line:

  Check(dbiGetCursorForTable(Value.DbHandle, pchar(Value), nil, hCur));

Any ideas? Thanks, Tom.        
0
 
LVL 3

Expert Comment

by:rickpet
ID: 1347954
Okay this works...opps on the pchar value...should be pchar(Value.TableName) not pchar(Value)

function TForm1.TableCount(Value: TTable): longint;
{to use the function, pass in  TTable}
var
   hCur: hDBICur;
begin
   if not Value.Active then
     Value.open;
   Result := 0;
   Check(dbiGetCursorForTable(Value.DbHandle, pchar(Value.TableName), nil, hCur));
   Check(DbiGetRecordCount(hCur, Result));
(*     Check(DbiCloseCursor(hCur));
Don't need to close as dbiGetCursorForTable only returns an existing cursor.
*)
end;

0
 

Author Comment

by:tomcorcoran
ID: 1347955
Rick,

That worked geat, I shoud have checked the BDE help myself. Thanks for the DBiCloseCursor info. Put in a dummy answer and I'll grade. Tom.
0
 
LVL 3

Expert Comment

by:rickpet
ID: 1347956
Tom...this one's on me...

I owe you...for that last one...

Also you don't need to even use...
   Check(dbiGetCursorForTable(Value.DbHandle, pchar(Value.TableName), nil, hCur));

since Table1.handle is a hDBICur.
from TBDEDataSet help
property Handle: HDBICur;

Rick
0
 

Author Comment

by:tomcorcoran
ID: 1347957
Rick,

Nice one. After all that it come down to:

function TableCount(tbl: TTable): longint;
{ the TTable must be open }
begin
   Check(DbiGetRecordCount(tbl.Handle, Result));
end;

That's generous of you. Should I just delete?

Tom.

0
 
LVL 3

Expert Comment

by:rickpet
ID: 1347958
Yes...

Rick
0
 
LVL 3

Expert Comment

by:rickpet
ID: 1347959
or just set the value to 0

Rick
0
 

Author Comment

by:tomcorcoran
ID: 1347960
Thing is I'd like to make this available, you can't decrease the points. I have no worries giving them to you. Tom.
0
 
LVL 3

Accepted Solution

by:
rickpet earned 50 total points
ID: 1347961
Okay then...I'll tell you what...I'll write a component for you...something like TStatusbar that will use what I call Beveled Labels.  They're like Labels(low on resources) but have bevels like panels.  Email me for the component rickpet@airmail.net

Rick
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now