.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  
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 - 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

    - 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 5 hosted by Hostway
    Stay green...Green IT