.NET
  Home arrow .NET arrow Page 10 - 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  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
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 / 17
    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 - Classes and Objects


    (Page 10 of 10 )

    A class is a value type that can contain data, properties, methods, and operators. Delphi's object model is discussed in much greater detail later in the "Using Delphi Objects" section of this chapter, so this section covers just the basic syntax of Delphi classes. A class is defined as follows:

    Type
      TChildObject = class(TParentObject)
      public
        SomeVar: Integer;
        procedure SomeProc;
      end;

    This declaration is equivalent to the following C# declaration:

    public class TChildObject: TParentObject
    {
      public int SomeVar;
      public void SomeProc() {};
    }

    Methods are defined in the same way as normal procedures and functions (which are discussed in the section "Procedures and Functions"), with the addition of the classname and the dot symbol:

    procedure TChildObject.SomeProc;
    begin
      { procedure code goes here }
    end;

    Delphi's . symbol is similar in functionality to C# and Visual Basic .NET's . operator when referencing members.

    Type Aliases

    The Delphi language has the capability to create new names, or aliases, for types that are already defined. For example, if you want to create a new name for an Integer called MyReallyNiftyInteger, you could do so using the following code:

    type
      MyReallyNiftyInteger = Integer;

    The newly defined type alias is compatible in all ways with the type for which it's an alias, meaning, in this case, that you could use MyReallyNiftyInteger anywhere in which you could use Integer.

    It's possible, however, to define strongly-typed aliases that are considered new, unique types by the compiler. To do this, use the type reserved word in the following manner:

    type
      MyOtherNeatInteger = type Integer;

    Using this syntax, the MyOtherNeatInteger type will be converted to an Integer when necessary for purposes of assignment, but MyOtherNeatInteger will not be compatible with Integer when used in var and out parameters. Therefore, the following code is syntactically correct:

    var
      MONI: MyOtherNeatInteger;
      I: Integer;
    begin
      I := 1;
      MONI := I;

    On the other hand, the following code will not compile:

    procedure Goon(var Value: Integer);
    begin
      // some code
    end;

    var
      M: MyOtherNeatInteger;
    begin
      M := 29;
      Goon(M); // Error: M is not var compatible with Integer

    In addition to these compiler-enforced type compatibility issues, the compiler also generates runtime type information for strongly-typed aliases. This enables you to create unique property editors for simple types, as you'll learn in Chapter 8, "Mono—A Cross Platform .NET Project."

    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.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

     

    .NET ARTICLES

    - Building Applications with Windows Workflow ...
    - Building the Data and Business Layers Using ...
    - The Transformed XML Explorer in MFC
    - List Control and Property Grid with the MFC ...
    - Font, Shell and Masked Edit Controls for MFC
    - Color, Link and Image Editor Controls for M...
    - New Controls for MFC
    - The Windows Ribbon Framework
    - Markup Language for the Ribbon Framework
    - Visually Upgrade Your MFC Project
    - New Features for the Statusbar in MFC
    - Working with the Statusbar in MFC
    - Iron Speed Design v60 Review
    - Binary and XML Serialization
    - Using CrystalReportViewer to Display Crystal...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek