delphi2007 教程

delphi2007 教程

首页 新随笔 联系 聚合 管理
  1013 Posts :: 0 Stories :: 28 Comments :: 0 Trackbacks
如何使用overload Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiBase/html/delphi_20061204165744296.html
我在unit1中定义了一个涵数funciton   xxx(cc):double,我想在unti5中重载,请问在unit5中该怎样用呢?还有就是在unit1中是否需在涵数funciton   xxx(cc):double后加上overload?请大家多多帮忙,谢谢?

同一个单元才用overload,多个单元互不相关

那么在同一个单元中又该怎样用呢?  
  是不是:funciton   xxx(cc:integer):double;overload;//已经声名过的.  
  funciton   xxx(cc:double):double;overload;//需要重载的.

观注...

只有一个   不用写overload就可以了

FUNCTION   micUn_GetChecksum(CONST   c_src:   AnsiString;CONST   c_bits:   Byte   =   32):   LongWord;overload;  
  FUNCTION   micUn_GetChecksum(CONST   c_src:   WideString;CONST   c_bits:   Byte   =   32):   LongWord;overload;  
 

摘录DELPHI   HELP   解释得很清楚了  
   
  You   can   declare   more   than   one   routine   in   the   same   scope   with   the   same   name.   This   is   called   overloading.   Overloaded   routines   must   be   declared   with   the   overload   directive   and   must   have   distinguishing   parameter   lists.   For   example,   consider   the   declarations  
   
  function   Divide(X,   Y:   Real):   Real;   overload;  
  begin  
      Result   :=   X/Y;  
  end;  
  function   Divide(X,   Y:   Integer):   Integer;   overload;  
  begin  
      Result   :=   X   div   Y;  
  end;

overload的用法已经有人解释的很清楚了  
  如果在同一个类中,有两个函数或过程,他们的功能很相似,但是需要传入的参数值不同,可以考虑用overload实现,这样在调用的时候,系统会根据传入的参数表自动判断需要调用的是哪个函数。

posted on 2009-04-22 10:43 delphi2007 阅读(158) 评论(0)  编辑 收藏 引用
只有注册用户登录后才能发表评论。