The Delphi Language, Part 1
(Page 1 of 10 )
The book
Delphi for .NET Developer's Guide, by Xavier Pacheco, (Sams, ISBN: 0-672-32443-1, 2004) includes this chapter by co-author and Delphi expert Steve Teixeira. This part of the chapter covers types of comments, parentheses in calls, default value parameters, Delphi language's structured style of variable declaration, differences between C# constants and Delphi constants, operators, variants, arrays and records and how Delphi's strongly-typed nature enables it to perform a sanity check of your code.
This chapter covers Delphi's underlying language, Object Pascal. First, you'll receive an introduction to the basics of the Delphi language, such as language rules and constructs. Then, you'll learn about some of the more advanced aspects of the Delphi language, such as classes and exception handling. This chapter assumes that you have some experience with other high-level computer languages. Therefore, it does not teach the concepts associated with programming languages, but rather on how to express those concepts in Delphi. By the time you're finished with this chapter, you'll understand how programming concepts such as variables, types, operators, loops, cases, exceptions, and objects work in Delphi and how many of these elements relate to the underlying .NET Framework. To provide additional practical grounding, we will draw comparisons where appropriate with Delphi's more widely used .NET cousins, C# and Visual Basic .NET.
It's All about .NET Delphi 8 produces applications that run completely within the context of the Microsoft .NET Framework. Therefore, the capabilities and features of Delphi 8's compiler must be subject to the capabilities and features of the underlying .NET Framework. This notion might be vaguely disconcerting for those coming into the .NET from the native code world. A native code compiler can essentially do anything it wants—its capabilities limited only by the desires of the compiler vendor. In .NET development, literally everything one might do—even something as trivial as adding two integers together—boils down to the compiler generating code that manipulates features and types of the .NET Framework.
Rather than producing native code, a .NET compiler such as Delphi 8 produces code in a format called Microsoft Intermediate Language, or MSIL, which is the lowest-level representation of application instructions.
Note - Chapter 2 discusses the just-in-time (JIT) compilation nature of the .NET Framework. Now might be a good time to review that information.
Comments
The Delphi language supports three types of comments: curly brace comments, parenthesis/asterisk comments, and double backslash comments. Examples of each type of comment follow:
{ Comment using curly braces }
(* Comment using paren and asterisk *)
// double backslash comment The first two types of comments are virtually identical in behavior. The compiler considers the comment to be everything between the open-comment and close-comment delimiters. For double backslash comments, everything following the double backslash until the end of the line is considered a comment.
Note - You cannot nest comments of the same type. Although it is legal syntax to nest comments of different types inside one another, we don't recommend the practice. Here are some examples:
{ (* This is legal *) }
(* { This is legal } *)
(* (* This is illegal *) *)
{ { This is illegal } }
Another handy technique for disabling a body of code, particularly when different kinds of comments are used in the code, is to use the $IFDEF compiler directive. For example, the following code uses $IFDEF to comment out a block of code:
{$IFDEF DONTCOMPILEME}
// imagine a bunch of code here
{$ENDIF}
Because the DONTCOMPILEME identifier is not defined, the code inside the $IFDEF is effectively commented out.
This chapter is from Delphi for .NET Developer's Guide, by Xavier Pacheco (Sams, 2004, ISBN: 0-672-32443-1). Check it out at your favorite bookstore today.
Buy this book now. |
Next: Procedures and Functions >>
More .NET Articles
More By Xavier Pacheco