getRelativeTimeMs


function getRelativeTimeMs: integer;

Return the current time in milliseconds. Note that the return value is 32-bit integer that can represent only 2^32 milliseconds, which is a little bit over 48 days. So every 48 days, this value is reset and starts counting from 0. Do not use this function to determine the current date, but it can be used for implementing timers in an application.

Consider a simple game (such as Tetris, for example) that needs to move the block down each second. Also, the game should move the block left or right when the user presses the left/right key on the keypad. The main program loop could be implemented as follows:

  ...
  lastSavedTime := getRelativeTimeMs; { initialize the timer }
  repeat
    { read and process the keypad input }
    key := getKeyClicked;
    if keyToAction(key) = GA_LEFT then moveLeft;
    if keyToAction(key) = GA_RIGHT then moveRight;

    { check if 1 second has passed }
    if ((getRelativeTimeMs - lastSavedTime) > 1000)
    or (getRelativeTimeMs < lastSavedTime)  { check if the timer is reset after 48 days }
      then
      begin
        lastSavedTime := getRelativeTimeMs;
        moveDown;
      end;
  until gameOver;
  ...