query1.sql.text:='select count(*) as cnt_all from table1';
query1.active:=true;
showmessage('total records is '+inttostr(query1.fieldbyname('cnt_all').asinteger));
i := 1;
tmp := table1.fields[0].value;//should be key
table1.disablecontrols;
table1.top;
while(table1.fields[0].value <> tmp) do
begin
table1.next;
inc(i);
end;
table1.enablecontrols;