.NET
  Home arrow .NET arrow Page 11 - The Delphi Language, Part 2
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 2
By: Xavier Pacheco
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 14
    2004-07-13

    Table of Contents:
  • The Delphi Language, Part 2
  • Out Parameters, Constant Parameters, and Open Array Parameters
  • Scope and Units and Namespaces
  • The uses Clause and Circular Unit References
  • Object-Oriented Programming
  • Using Delphi Objects
  • Methods
  • Class References and Properties
  • Events
  • Visibility Specifiers, Friend Classes and Class Helpers
  • Nested Types, Operator Overloading and Attributes
  • Interfaces
  • Using Interfaces, SEH
  • Exception Classes

  • 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 2 - Nested Types, Operator Overloading and Attributes


    (Page 11 of 14 )

    The Delphi language allows for a type clause to appear with a class declaration, effectively nesting types within a class. Such nested types are referenced using a NestedType.OuterType syntax, as shown in the following code example:

    type
      OutClass = class
        procedure SomeProc;

        type
          InClass = class
            procedure SomeOtherProc;
          end;

      end;

      var
        IC: OutClass.InClass;

    Operator Overloading

    The Delphi language supports the overloading of select operators for classes and records. The syntax for overloading an operator is as straightforward as declaring a class method with a specific name and signature. A complete list of overloadable operators can be found in the Delphi online help under the Operator Overloads topic; however, the following code example demonstrates how you might overload the + and operators of a class:

      OverloadsOps = class
      private
        FField: Integer;
      public
        class operator Add(a, b: OverloadsOps): OverloadsOps;
        class operator Subtract(a, b: OverloadsOps):   OverloadsOps;
      end;

    class operator OverloadsOps.Add(a, b: OverloadsOps): OverloadsOps;
    begin
      Result := OverloadsOps.Create;
      Result.FField := a.FField + b.FField;
    end;

    class operator OverloadsOps.Subtract(a, b: OverloadsOps): OverloadsOps;
    begin
      Result := OverloadsOps.Create;
      Result.FField := a.FField - b.FField;
    end;

    Note that the overloaded operators are declared as class operator and take the declaring class as parameters. Because the + and – operators are binary, they also return the declaring class.

    Once declared, the operators can be used in a manner similar to that shown here:

    var
    O1, O2, O3: OverloadsOps;
    begin
      O1 := OverloadsOps.Create;
      O2 := OverloadsOps.Create;
      O3 := O1 + O2;
    end;

    Attributes

    One of the more exciting features of .NET platform is the realization of attribute-based development, which had been on the drawing board of a few different programming languages for the past several years. Attributes provide a means to tie metadata to language elements such as classes, properties, methods, variables, and so on that provide extended information about those elements to their consumers.

    Attributes are declared using square bracket notation before the element to be augmented. For example, the following code demonstrates the use of the DllImport attribute, which signals to .NET that the method should be imported from the specified DLL:

    [DllImport('user32.dll')]
    function MessageBeep(uType : LongWord) : Boolean; external;

    Attributes are used liberally in .NET. For example, the Browsable attribute on a property determines whether it should be displayed in the Object Inspector:

    [Browsable(True)]
    property Foo: string read FFoo write FFoo;

    .NET's attribute system is quite extensible because attributes are implemented as classes. This allows you to extend the attribute system without limit because you can create your own attributes either from scratch or by inheriting from existing attribute classes and use these new attributes in other classes.

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