Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8994793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:30:30+00:00 2026-06-15T23:30:30+00:00

For whatever reason, I can not figure out how to identify the number of

  • 0

For whatever reason, I can not figure out how to identify the number of results in a given page. I have a list of data, and a property PageSize which identifies how many results should fit in one page. Let’s say there’s 120 results and the page size is 25. That means there should be a total of 5 pages, the first 4 having 25 records, and the 5th having just 20 records. Right now, the results I’m getting are all over the board, for example I might get 50 when it’s supposed to be 20.

I’m writing this function to return the number of results in a specified page, but I can’t seem to get the simple math right (I was never very good at math). There are no actual lists per page where I can simply read Count to identify the number of records in that page – I need to dynamically calculate it, using this function.

Refer to the line of code just under CALCULATION DONE HERE:

function TMyData.SizeOfPage(const Index: Integer): Integer;
begin
  //Index = Page Number (0 ... MAX)
  //Result = Number of results in given page
  //PageCount = Total number of pages (from other function)
  //RecordCount = Total number of records (all pages)
  Result:= 0; //Default
  //Validate index bounds
  if (Index >= 0) and (Index < PageCount) then begin
    if Index < PageCount-1 then begin
      //Just return full size of one page
      Result:= PageSize;
    end else begin
      //Return number of records in the last page
      //--- CALCULATION DONE HERE ---
      Result:= RecordCount - Trunc(RecordCount / PageSize);
    end;
  end else begin
    raise Exception.Create('Page index out of bounds ('+IntToStr(Index)+')');
  end;
end;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T23:30:31+00:00Added an answer on June 15, 2026 at 11:30 pm

    I see no reason to use floating point arithmetic here. I always avoid floating point arithmetic if integer arithmetic suffices.

    I would write it like this:

    ItemsOnLastPage := 1 + (RecordCount-1) mod PageSize;
    

    Or perhaps this version:

    ItemsOnLastPage := RecordCount - (PageCount-1)*PageSize;
    

    This is particularly easy to understand. You subtract the records shown on all the full pages, and what is left are the records on the last page.

    As far as PageCount goes, you can calculate it like so:

    PageCount := (RecordCount+PageSize-1) div PageSize;
    

    Thanks to @Rob for his insight.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay, for whatever reason I can't seem to figure this little problem out. I
I cannot figure out json for whatever reason, i don't understand why i cannot
...which I cannot seem to figure out, for whatever reason. I've tried cleaning my
On whatever reason this is not working (says 'file not found'), set in=c:\myprogram\_save cd
For whatever reason, std::cout does not display anything with my application. The description of
I have an ASP.NET web application that, for whatever reason, when it is deployed
I have a DateTime field in my form. For whatever reason, everytime I submit
Whatever I do, whatever headers I elaborate, it does not work. Even I have
Been fighting with Linux for the past few days. For whatever reason I can't
Not sure if this is a bug in jQuery 1.4.2 - I can't figure

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.