.NET
  Home arrow .NET arrow Page 4 - The Delphi Language, Part 1
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
.NET

The Delphi Language, Part 1
By: Xavier Pacheco
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 16
    2004-07-07

    Table of Contents:
  • The Delphi Language, Part 1
  • Procedures and Functions
  • Constants, Operators
  • Delphi Language Types
  • Variant Types
  • Variants in Expressions
  • Arrays
  • Records and Sets
  • Pointers
  • Classes and Objects

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    The Delphi Language, Part 1 - Delphi Language Types


    (Page 4 of 10 )

    One of the Delphi language's greatest features is that it's strongly typed, making it an excellent fit for the .NET platform. This means that actual variables passed to procedures and functions must be of the same type as the formal parameters identified in the procedure or function definition—very little is done for you in terms of implicit type conversion. Delphi's strongly-typed nature enables it to perform a sanity check of your code—to ensure that you aren't trying to put a square peg in a round hole. After all, the easiest bug fixes are the ones the compiler tells you to perform!

    Objects, Objects Everywhere!

    One of the most important notions regarding fundamental types in the .NET version of the Delphi compiler is that they are all value types capable of implicit conversion to classes. This conversation between value and object and back again is known as boxing and unboxing in .NET parlance. Integers, strings, floating points, and all of the rest are not implemented as primitive concepts in the compiler, as in Win32, but instead map to value types provided either by the .NET Framework or by Borland's RTL or VCL. Unlike Win32 Delphi, these value types can have their own procedures and functions in addition to those available in corresponding classes created by the implicit boxing and unboxing of these types. This allows for a kind of syntax that might be foreign for those coming from native compilers (although perhaps familiar for those experienced with languages such as Java or SmallTalk):

    var
      S: string;
      I: Integer;
    begin
      I := 42;
      S := I.ToString; // can call a method on an Integer!
    end;

    Note - The string type is used heavily in development. This is not to say that other types are not, but there are some special considerations when using strings. Chapter 11 addresses strings specifically; therefore, you will not see detailed coverage of them here.


    A Comparison of Types

    Delphi surfaces most of the primitive types available in the CLR. Table 5.5 compares and contrasts the base types of the Delphi language with those of C# and the CLR. This table also indicates whether each type is compliant with the CLS.

    Table 5.5 A Delphi-to-C#-to-CLR Type Comparison

    Variable range

    Delphi

    C#

    CLR

    CLS Compliant?

    8-bit signed integer

    ShortInt

    sbyte

    System.SByte

    No

    8-bit unsigned integer

    Byte

    byte

    System.Byte

    Yes

    16-bit signed integer

    SmallInt

    short

    System.Int16

    Yes

    16-bit unsigned integer

    Word

    ushort

    System.UInt16

    No

    32-bit signed integer

    Integer

    int

    System.Int32

    Yes

    32-bit unsigned integer

    Cardinal

    uint

    System.UInt32

    No

    64-bit signed integer

    Int64

    long

    System.Int64

    Yes

    64-bit unsigned integer

    UInt64

    ulong

    System.UInt64

    No

    single precision float

    Single

    float

    System.Single

    Yes

    double precision float

    Double

    double

    System.Double

    Yes

    fixed-point decimal

    None

    decimal

    System.Decimal

    Yes

    Delphi fixed-point decimal

    Currency

    None

    None

    No

    date/time

    TDateTime*

    None

    System.DateTime

    Yes

    variant

    Variant, OleVariant

    None

    None

    No

    1-byte character

    AnsiChar

    None

    None

    No

    2-byte character

    Char, WideChar

    char

    System.Char

    Yes

    Fixed-length byte string

    ShortString

    None

    None

    No

    Dynamic 1-byte string

    AnsiString

    None

    None

    No

    Dynamic 2-byte string

    string, WideString

    string

    System.String

    Yes

    Boolean

    Boolean

    bool

    System.Boolean

    None


    *TDateTime is a record that wraps a System.DateTime with methods and operator overloads that makes it behave very much like System.DateTime , but with additional behavior to be compatible with Win32 Delphi's TDateTime type. 

    Characters

    Delphi provides three character types:

    • WideChar—This CLS-compatible character is two bytes in size and represents a Unicode character.

    • Char—This is an alias for WideChar. In Win32 versions of Delphi, Char was an AnsiChar.

    • AnsiChar—An old school one-byte ANSI character.

    Never assume the size of a Char (or any other type, for that matter), in your code. Instead, you should use the SizeOf() function where appropriate.


    Note - The SizeOf() standard procedure returns the size, in bytes, of a type or variable.


    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.

    More .NET Articles
    More By Xavier Pacheco


     

    .NET ARTICLES

    - Using CrystalReportViewer to Display Crystal...
    - Creating Summary .Net Crystal Reports
    - More on Commands, Input and the WPF
    - Grouping and Aggregating When Querying LINQ ...
    - Commands, Input and the WPF
    - Keyboard and Ink Input with WPF
    - Mouse Input and the WPF
    - Input with Windows Presentation Foundation
    - Introducing LINQ with XML and Databases
    - An Introduction to LINQ
    - Querying LINQ to SQL: Basics
    - Completing a Simple Storefront with LINQ
    - Knowing Your Environment: the System.Environ...
    - Creating the Home Page for a Simple Storefro...
    - LINQ Quickly with Language Integrated Queries

     
    Best Practices for Windows Vista Migration Presentation
    Dell and Microsoft recently held a series of face-to-face seminars entitled, &qu....

     
    Creating a Culture for Code Reuse
    If you oversee development teams you know that like it or not proprietary and ex....

     
    Keys to Web Application Acceleration: Advances in Delivery Systems
    Accelerate Web apps by up to 5x. Ensure significantly faster access to the Web a....

     
    Optimizing Application Monitoring
    Tired of finding out from your customers that you're offline? This white paper e....

     
    Solaris to Solaris Migration -- Migrating applications from Sun SPARC to Dell PowerEdge R900
    This comprehensive Migration Guide reviews the approach that Principled Technolo....

     




    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
    Stay green...Green IT