{Kaynak/Yazar: Ido Kanner}
function TForm1.GetNextNumber : integer;
begin
qryMain.Active := False;
qryMain.SQL.Clear;
qryMain.SQL.Add('Select Max(FieldToIncrease) from tblMain where (Cheking >=1);');
qryMain.Active := True; //We executed the query
if qryMain.RecordCount >= 0 then
result := qryMain.FieldByName('FieldToIncrese').AsInteger +1;
else result := 1;
end;
procedure TForm1.SetNextNumber;
begin
//You must first see if the table is in insert/update mode before using this procedure.
tblMain.FieldByName('FieldToIncrese').AsInteger := GetNextNumber;
end;