erlying value type. For the following code,
TObject(12).ToString
the code TObject(12) boxes an integer into an object.
Boxing of value types in Delphi for .NET is a requirement. Boxing support is not planned for Win32 or Linux Delphi language implementations.
Records with inheritance
Delphi records will be implemented as value types in CLR. Record inheritance is an aspect of value types. Records with non-virtual methods is another aspect of value type support.
Records with methods
The declaration of methods on TRecord is supported. These behave as static non-virtual methods.
Sealed classes
A sealed class cannot be inherited from. Value types can only inherit from abstract value type classes, and only sealed value type classes can be instantiated. Value types are highly deterministic, and decidedly non-polymorphic.
Final methods
The final directive on a virtual method (or override) indicates that this method cannot be overridden in descendent classes. Descendents may still introduce new virtual methods with the same name as the inherited method, but since they do not override the inherited method (occupy the same vmt slot as the inherited method), they do not participate in polymorphic calls to the inherited method.
Possible Enhancements
Multicast events
With multicast events, you can have multiple listeners for each event. This event model is different from the Win32 event model, where an event is consumed and discarded by the first component responding to it. With event listeners, multiple components can respond to the same message (for example, all controls could respond to a "repaint" event).
In this event listener model, you can only remove your own listener. Include() and Exclude() are standard procedures overloaded to operate on events for adding or removing an event listener. Traditional singleton event semantics are supported through := assignments. If a singleton event is used with an assignment, it overrides Include() or other listeners.
Support for multicast events in Delphi for .NET is a requirement. Support for multicast events may appear in future releases of Delphi for Win32 and Linux.
Interface method resolution
Interface method resolution provides a convenient shorthand for implementing methods referenced in an interface. By default, the compiler attempts to bind a method name to a method of the same name in the class implementing the interface. With the following code,
Type
TMyClass = class(TBaseClass, IFoo)
procedure FooBar(paramlist);
procedure IFoo.Bar = FooBar;
end;
The new version would be:
Type
TMyClass = class(TBaseClass, IFoo)
procedure IFoo.Bar(paramlist);
end;
A reference to TMyClass.IFoo.Bar is then valid.
When multiple interfaces are used, interface method resolution becomes even more valuable. The following code illustrates:
IFoo1 = interface
procedure Bar;
end;
IFoo2 = interface
procedure Bar;
end;
TSomeClass = class(TBaseClass, IFoo1, IFoo2)
procedure IFoo1.Bar;
procedure IFoo2.Bar;
end;
Array property overloads
Array property overloads will also be supported. The following example shows the probable syntax for overloading array property references.
TSomeClass = class
property Item[Index: string]: string
read GetItem write SetItem; overload;
property Item[Index: integer]: string
read GetItem write SetItem; overload;
property Names: string read GetNames write SetNames;
overload;
property Names[Index: Integer]: string
read GetNames write SetNames; overload;
function GetItem(Index: string): string; overload;
procedure SetItem(Index:string; Value: string); overload;
function GetItem(Index: Integer): string;
overload;
procedure SetItem(Index: Integer; Value: string);
overload;
function GetNames: string; overload;
procedure SetNames(Value: string); overload;
function GetNames(Index: Integer): string;
overload;
procedure SetNames(Index: Integer; Value: string);
overload;
end;
Overload of array properties is required for CLS compliance. For example, the CLR NameValueCollection overloads integer and string index references for the default Item property, as does this code snippet example above.
Conclusion
This document is intended to introduce some of the new features and concepts under research for the Delphi for .NET compiler. While every attempt has been made to keep this information accurate, all of it is subject to change. Compiler support for .NET has provided some exciting opportunities for enhancement to the Delphi language. The language enhancements discussed here are for the Delphi for .NET compiler unless otherwise stated. Hopefully, you like what you see so far.
Stay tuned to this web site, as more articles on Delphi for .NET are coming very soon.
Add or View comments on this article
Article ID: 28972 Publish Date: August 06, 2002 Last Modified: August 05, 2002
Made in Borland® Copyright© 1994-2002 Borland Software Corporation. All rights reserved. Legal Notices, Privacy Policy
上一页 [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文件的代…
|