转至繁体中文版     | 网站首页 | 图文教程 | 资源下载 | 站长博客 | 图片素材 | 武汉seo | 武汉网站优化 | 
最新公告:     敏韬网|教学资源学习资料永久免费分享站!  [mintao  2008年9月2日]        
您现在的位置: 学习笔记 >> 图文教程 >> 软件开发 >> Delphi程序 >> 正文
Delphi for .Net 编译器预览 - by John Kaster         ★★★★
TObject System.Object String System.String Variant System.ValueType Records System.ValueType Exception System.Exception TComponent System.ComponentModel.Component Database connectivity ADO.NET (and DataSnap direct drivers) RIO Web Services On top of System.Web.Services GUI System.Windows.Forms plus VCL

Assemblies and Delphi

The Delphi for .NET compiler treats CLR assemblies like Delphi packages. The compiler supports direct symbol importing from metadata. Header file translations are no longer needed. Symbols can be imported from any Common Language Specification (CLS) compliant .NET assembly, produced by any .NET language tool. Conceptually, every .NET assembly contains the equivalent of a DCP (which is a collection of DCUs) and a BPL, all lumped into one file.

The compiler supports the -lu<name> switch to specify which assemblies to link with or allow access to. These assemblies do not have to be Delphi assemblies. Any CLR assembly can be used directly with Delphi for .NET, with no translations or conversions. Just as you use -lu for Delphi packages, you can use -lu for any CLR assembly.

The Delphi package syntax produces assemblies. Furthermore, the package syntax will still provide the option of linking referred code directly into your exe, or making it an external reference.

The .NET assemblies don''''t give you the option of internal or external linking of code. You can support internal or external linking by distributing the DCUs as well as DCPs + BPLs. You cannot link code compiled in a package into an exe. You have to have a DCU (or source) to do that. The DCCIL compiler behaves the same as the DCC32 compiler.

You should also know that Delphi for .NET will preserve the case for the namespaces you create. C#''''s recognition of namespaces is case sensitive, so if you use a Delphi for .NET assembly with C#, you will need to match the original case of the namespace you created. Delphi''''s recognition of namespaces is not case sensitive, so if you don''''t keep this behavioral difference of the languages in mind, you might run into problems later.

Delphi Language Enhancements

I''''m sure you were all looking closely at the code above, even though I told you it would change. Some of the enhancements to Delphi are obvious by looking at the source code, but not all of them are demonstrated in the above code sample.

Let''''s look at a partial list of Delphi language enhancements.

Unit namespaces

By examining the above source code, one obvious change should be the support for unit namespaces. Namespaces allow you to access units with fully qualified identifiers, such as:


uses Borland.Delphi.SysUtils;

The Delphi unit defines its own namespace with dotted names in the unit identifiers and file names. (The file name and unit name still match, with the ".pas" omitted from the unit name.)

Project namespace

You can configure project-specific namespace resolution. Project namespaces are a great way to eliminate uses clause IFDEFs. The project namespace will determine how the unit name references are fully resolved.

Project namespace search path

There will also be support for a project namespace search path, which supports searching the namespace path for unqualified unit names on the search path. Consider this hypothetical example:


uses Forms;

This reference would resolve to Borland.VCL.Forms for a VCL project, and Borland.CLX.Forms for a CLX project. Clearly, this will make code for cross-platform development (such as .NET, Win32, and Linux) much easier to write and maintain.

Default project namespace

You can also create units that can be compiled into multiple project namespaces. For example,


unit MyControl;

would compile to Borland.VCL.MyControl.dcuil for a VCL project, and Borland.CLX.MyControl.dcuil for a CLX project.

Qualified identifiers

Reserved words or keywords are allowed after the first identifier. For example, in the following code:


var
  foo : System.Label;

Qualified identifiers can appear in type expressions, but not in identifier declarations. System.Label would be allowed as a valid type expression although label is a reserved word in Delphi. Future compiler plans for the extended identifier syntax include allowing the use of Unicode/UTF8 identifiers after the first "standard" identifier.

The Common Language Specification includes this extended identifier syntax. The dccil compiler will provide access to all CLS compliant symbols in CLR assemblies.

Nested types

Consider the following code:


type
TMyClass = class
  Fdata: Integer;
  const foo = 12;
  type TNestedClass = class
    procedure Hello;
  end;
  procedure Green;
end;
...
var
  MyClass : TMyClass;
  MyNest: TMyClass.TNestedClass;
...
begin
  MyClass.Fdata := 15;
  MyNest.TNestedClass := TMyClass.TNestedClass.Create;
  MyNest.Hello;
  MyClass.Green;
end;

The TNestedClass type is nested inside of the TMyClass type, but doesn''''t affect instances of TMyClass because data fields defined in TMyClass.TNestedClass do not occupy space in instances of TMyClass. Nested types are an extension of the namespace idea; logical containment by naming convention, with no physical manifestation.

In the above example, MyNest is not freed because it will be garbage-collected by the .NET runtime.

Custom Attributes

Delphi for .NET will support standard attributes, such as Conditional, Obsolete, Serializable, and web methods. You will also be able to create custom attributes, such as those displayed here:


type
  [ FooAttribute(''''Hello'''', 23) ]
  TMyClass = class
    [ SpecialDataAttribute ]
    Fdata: Integer;
    [ WebMethod, DebuggerStepThrough ]
    function SampleCount: Byte;
  end;

Declaring custom attributes

Delphi allows you to create custom attributes you can use for any of your .NET application source code, such as the TQuantumAttribute declared here:


type
  TQuantumAttribute = class(TCustomAttribute)
    constructor Create;
    constructor Create(Name: String);
    property Name: String ...;
    property Spin: Double ...;
    property Color: TQuarkColor ...;
  end;

A poster child for custom attributes might be the DLLImportAttribute. The Borland.Win32.Windows unit will be using that attribute for indicating the requirement for Windows run-time DLLs. CLR supports more options for referencing external DLL functions than regular old PE DLL Imports. Rather than add more special syntax to the language to cover those additional CLR-specific options, the additional info can be carried in an attribute. The compiler can remain blissfully ignorant of the payload for all but a handful of custom attributes.

Class (static) data

You can have class variables in your objects. This allows you to do things like perform instance counts or track information that is class specific rather than instance specific in your objects.


type
TMyClass = class
  class Fdata: Integer;
  class property Foo: String ...;
  class procedure One;
  class static procedure Two;
end;

Class properties

Class properties work like class fields. The getters and setters must be class methods or class fields.

Class static methods

Class static methods work the same as traditional Delphi class methods, except that there is no "self" parameter available in the method body. This is a CLR requirement because some languages do not support the hybrid behaviors Delphi has, where you can have routines that are not part of an object. Traditional Delphi class methods (which do have a "Self" in the body of the method) will also be supported.

Value types

Types can be "boxed" into object wrappers. These value types are not reference types. They are the actual instance of the type. Value semantics are supported for assignment and copying data. Record types are an example of value types in Delphi. Records can inherit from other records, and records can contain non-virtual methods, properties, and nested types.

When value types are boxed, a fresh copy of the value is made and a distinct object reference is returned. This distinct object reference is a reference to data that is completely independent of the und

上一页  [1] [2] [3] [4]  下一页


[C语言系列][C#防止反编译].NET 产品版权保护方案 (.NET源码加…  [互联动态].NETFramework3.0新特性介绍与问答翻译
[Web开发]asp.net代码空格显示为……点号的原因及解决办法  [Web开发]asp.net调用压缩软件对文件进行压缩与解压缩的代码
[Web开发]详细介绍asp.net获取日期时间的各种格式的函数  [Web开发]如何将JS文件编译到ASP.NET项目里的DLL文件中
[Web开发]asp.net加密口令的最简单方法  [Web开发]目前asp.net开发主流工具软件介绍
[Web开发]asp.net中的反射介绍  [Web开发]制作留言板不使用数据库之asp.net操作XML文件的代…

Delphi for .Net 编译器预览 - by John Kaster

作者:闵涛 文章来源:闵涛的学习笔记 点击数:3211 更新时间:2009/4/23 18:39:15
sely, but also because compatibility type mappings will be provided.

The following table shows some classes and technology areas that map easily between Delphi and the .NET runtime.

Delphi for .NET .NET CLR
教程录入:mintao    责任编辑:mintao 
  • 上一篇教程:

  • 下一篇教程:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
      注:本站部分文章源于互联网,版权归原作者所有!如有侵权,请原作者与本站联系,本站将立即删除! 本站文章除特别注明外均可转载,但需注明出处! [MinTao学以致用网]
      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)

    同类栏目
    · C语言系列  · VB.NET程序
    · JAVA开发  · Delphi程序
    · 脚本语言
    更多内容
    热门推荐 更多内容
  • 没有教程
  • 赞助链接
    更多内容
    闵涛博文 更多关于武汉SEO的内容
    500 - 内部服务器错误。

    500 - 内部服务器错误。

    您查找的资源存在问题,因而无法显示。

    | 设为首页 |加入收藏 | 联系站长 | 友情链接 | 版权申明 | 广告服务
    MinTao学以致用网

    Copyright @ 2007-2012 敏韬网(敏而好学,文韬武略--MinTao.Net)(学习笔记) Inc All Rights Reserved.
    闵涛 投放广告、内容合作请Q我! E_mail:admin@mintao.net(欢迎提供学习资源)

    站长:MinTao ICP备案号:鄂ICP备11006601号-18

    闵涛站盟:医药大全-武穴网A打造BCD……
    咸宁网络警察报警平台