Solved

successive table record count problems

Posted on 1998-05-26
17
227 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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
 

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

749 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