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 C# or Visual Basic .NET. If that has been your practice, you’re going to have to retrain yourself a little in order to use variables in the Delphi language. Delphi 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 freewheeling code like this:

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

In Delphi, any such code must be tidied up and structured a bit more to look like this:

procedure ...

Get Delphi for .NET 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.