Delphi2005学习笔记4——再谈NameSpace和Dll以及Package

2016-02-19 16:22 4 1 收藏

人生本是一个不断学习的过程,在这个过程中,图老师就是你们的好帮手,下面分享的Delphi2005学习笔记4——再谈NameSpace和Dll以及Package懂设计的网友们快点来了解吧!

【 tulaoshi.com - 编程语言 】

今天在BDN中看到一篇文章
  http://bdn.borland.com/article/0,1410,32765,00.html
  
  重要的部分摘抄如下
  

Executive Summary

•          Namespaces do not affect Delphi for Win32.

•          Namespaces are produced based on the unit name as follows:

•          If a unit name is dotted then the unit name up to the last dot is used.

•          If it is not dotted then the default namespace is used.

•          If there is no default namespace then the unit name is used.

•          Code converted from Delphi 8 may require some modifications.

•          Always use Packages not Libraries to create shareable assemblies.

•          Delphi will always refer to types by their full unit name.

•          Other languages will need to refer to types using their namespace.

•          ASP.NET declarations, configuration files and .NET reflection always refer to types by their namespace.

•          If multiple units emit a public type with the same name into the same namespace, the assembly may be unusable
  
  

1)     Always Use Packages

Borland has always recommended not using library projects to create assemblies. In Delphi 2005, the compiler is stricter and will no longer allow you to compile an application referencing a Delphi ‘library’.
  Always use a package project to create .NET assemblies.
  
  

However, as with anything, there are exceptions to the rule and there are several situations where you need to use the namespace even though you are coding in Delphi.

 

One example is when you are using tags in ASPX, ASCX or ASMX files. If you create a web page called TWebForm in the file Application.­Pages.­WebForm1.­­pas then the page tag would be:

(本文来源于图老师网站,更多请访问https://www.tulaoshi.com/bianchengyuyan/)

 

%@Page Language="c#" Codebehind="WebForm1.pas" Inherits="Application.Pages.TWebForm1"%

 

Another is when passing type information to .NET in the form of strings, especially when using reflection based APIs and configuration files:

 

var c:TypeConverter;

c:=Assembly.CreateInstance('Sample.Controls.TConverter');

 

This slight difference commonly trips people up and is something you need to be careful of, especially when porting code from Delphi 8 or converting code from other languages.
  
  这就解释了我原来的疑问,在D2005中,新建一个.Net Dll,编译,在别的编译器中(C#),可以使用,但是在Delphi中自己却不能用,虽然用薄可以解决问题,但是包中添加资源很不方便,真是不知道Borland是怎么想的。

(本文来源于图老师网站,更多请访问https://www.tulaoshi.com/bianchengyuyan/)

来源:https://www.tulaoshi.com/n/20160219/1611881.html

延伸阅读
1.简介 EXCEPT和INTERSECT运算符使您可以比较两个或多个SELECT语句的结果并返回非重复值。 2.区别 EXCEPT运算符返回由EXCEPT运算符左侧的查询返回、而又不包含在右侧查询所返回的值中的所有非重复值。 INTERSECT返回由INTERSECT运算符左侧和右侧的查询都返回的所有非重复值。 3.注意事项 (1).使用EXCEPT或INTERSECT比较的结果集必须...
约定 //一个典型的用C#写就的HelloWorld程序 using System; class HelloWorld { public static void Main() { Console.WriteLine("Hello World !"); } } 我忘记自己第一次用C#向世界问好是在什么时候了,不过可以肯定我已经打过招呼了,那时候用的是beta1版。现在你可以到http://msdn.microsoft.com/downloads/default.asp?url=/downloads/sa...
1.简介: SQL Server 2005中的窗口函数帮助你迅速查看不同级别的聚合,通过它可以非常方便地累计总数、移动平均值、以及执行其它计算。 窗口函数功能非常强大,使用起来也十分容易。可以使用这个技巧立即得到大量统计值。 窗口是用户指定的一组行。 开窗函数计算从窗口派生的结果集中各行的值。 2.适用范围: 排名开窗函数和聚合开窗函...
一、概述 Borland 希望Delphi 2005 能成为Windows平台上的最终的完整解决方案,为此 Delphi 2005 集成了 Delphi, C#, Microsoft .NET Framework and Win32 ,支持图形用户接口(GUI), Web开发, 数据库、富客户端应用程序(rich-client applications)等多方面的开发, 集成软件生命周期管理(ALM)功能及快速开发(即RAD)的能力。在Del...
曾经听说过“bpl就是一种特殊的dll”,但是没有想到这句话具有这么大的意义。最近看到有人在属于某个dpk的Unit里面写export语句,觉得非常惊奇。但是遍查delphi的help,与export相关的都是library。今天看了《delphi源代码分析》,才知道上面这句话的含义。因此有下面的推论: 对dll工程来说,exports既可以写在工程文件里面,也可以...

经验教程

848

收藏

40
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部