Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

successive table record count problems

Posted on 1998-05-26
17
Medium Priority
?
233 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:boardtc
  • 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:boardtc
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
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!

 

Author Comment

by:boardtc
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:boardtc
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:boardtc
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:boardtc
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:boardtc
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:boardtc
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 200 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses
Course of the Month12 days, 15 hours left to enroll

971 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