unit
interface
uses
;The component used by the unit Example:ActiveX
{在这里加入的unit,在之后的代码中就可以直接使用它的成员,不需要unit加.限定成员位置,和VC的using很相像}
type
TypeName = class(BaseTypeName)
procedure functionName(param : Type)
private
{ Private declarations }
public
{ public declarations }
end
implementation
{$R*.dfm}
;The message handle function is the the class member function
procedure ClassName.FunctionName(param1:type...)
var
begin
end
var
;global member
{the class use the = operation to assign classnamea = classnameb}
{struct is the "packed record"}
{the referrence operation is ^ "^member"}
initialization
finalization
end
{Dephi 比VC++ 有了更多的封装,没有提供事件的机制,而提供了相应的方法来处理事件,很可能是语言提供了用来分配事件处理函数的关键字,这样达到了一定的对WINDOWS事件机制的封装效果}
{使用了非常简单的统一的方式来实现继承,类别名,就是=操作符}
{定义了一些特殊的关键字来实现结构体,packed record}
Delphi 使用了property 来实现属性功能 使用[Index: Integer] 来支持属性数组,Index是关键字。
枚举型数组:
TIdStatus = ( hsResolving,
hsConnecting,
hsConnected,
hsDisconnecting,
hsDisconnected,
hsStatusText,
ftpTransfer, // These are to eliminate the TIdFTPStatus and the
ftpReady, // coresponding event
ftpAborted); // These can be use din the other protocols to.
const
IdStati: array[TIdStatus] of string = (
RSStatusResolving,
RSStatusConnecting,
RSStatusConnected,
RSStatusDisconnecting,
RSStatusDisconnected,
RSStatusText,
RSStatusText,
RSStatusText,
RSStatusText);
这里就使用了TIdStatus来做为数组的索引.
非常有趣的Dephi异常处理:
raise object at address
这里的object是指一个从SysUnit.Exception类或其子类的实例.
而这里的address表示的是你所想指定引发异常的地址.
这个地址常常是堆栈中之前的函数地址,它其实才是真正引发异常的位置.
这个地址可以通过内连汇编来得到:
class procedure TList.Error(const Msg: string; Data: Integer);
function ReturnAddr: Pointer;
asm
MOV EAX,[EBP+4] //对,只要使用EBP寄存器就可以了
end;
begin
raise EListError.CreateFmt(Msg, [Data]) at ReturnAddr;
end;
但是这种功能是C++所不具有的,而且其它的语言一般也不具备.
Delphi语言没有new关键字,它是直接使用构造函数Create来生成一个新的对象.
C++中的catch使用except on来表示
待续...