Variables

You might be used to declaring variables off the cuff: “I need another integer, so I'll just declare one right here in the middle of this block of code.” This is a perfectly reasonable notion if you're coming from another language such as Java, C, or Visual Basic. If that has been your practice, you're going to have to retrain yourself a little in order to use variables in Object Pascal. Object Pascal requires you to declare all variables up front in their own section before you begin a procedure, function, or program. Perhaps you used to write free-wheeling code like this:

void foo(void)
{
  int x = 1;
  x++;
  int y = 2;
  float f;
  //... etc ...
}

In Object Pascal, any such code must be tidied up and structured a bit more to look like

Get Borland® Delphi™ 6 Developer's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.