Title: Easy function to show state and number of records of a table
Question: Here is a simple function that will show the current record and the total of them (eg: Record 2 of 10) and the state of the table, for a Paradox or dBase table
Answer:
The following assumes that you have all your TTables and TDataSources in a DataModule, called 'DM':
declare, in the datamodule, the following private procedure:
{--snip--}
procedure TDM.ShowCurrentRec(T: TTable; var S: String);
var
TheRec, Total: LongInt;
begin
TheRec := T.RecNo;
Total := T.RecordCount;
if TheRec = -1 then S := 'Inserting...'
else S := Format('Record %d of %d', [TheRec, Total]);
end;
{--snip--}
The procedure asks for 2 parameters: (1) the TTable object to test, and (2) a string (which will have its value modified) to describe the state of the table. Note that we check wether RecordCount is -1, what means that a new record is being inserted.
Now, to use this, you'll have to code the following for all datasources' OnDataChange event (remember: they are all in the datamodule):
{--snip--}
procedure TDM.DataSource1DataChange(Sender: TObject;
Field: TField);
begin
ShowCurrentRec(Table1, Form1.Caption);
end;
{--snip--}
Note thet the second parameter can be any string property; it may point to a label's caption or a global string variable.