VC++与Dephi的区别

本文介绍了Delphi编程语言的基础知识,包括单元(unit)、接口(interface)的使用方式,类型定义及异常处理等特性。此外还讲解了Delphi如何实现继承、属性及枚举类型的运用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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来表示

待续...
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值