Solved

successive table record count problems

Posted on 1998-05-26
17
224 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi 2010 Export to pdf 2 285
Internet Explorer View Settings Question 15 105
Show Listview image from database (String field) 5 112
update joined tables 2 27
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

919 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

14 Experts available now in Live!

Get 1:1 Help Now