unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs;type
  TForm1 = class(TForm)
    procedure Amethod(f:integer);overload;
    procedure Amethod(f1:string);overload;
  private
    { Private declarations }
  public
    { Public declarations }
  end;var
  Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Amethod(f:integer);
begin
//
end;procedure TForm1.Amethod(f1:string);
begin
//
end;end.
-----------------------------
我这样声明重载的过程Amethod,有错误,但我讲过程声明部分放入private或者public部分就能通过了.........
这是问题一..........
问题二,,将测试的重载函数放到一个新建的Unit中,重载函数的声明却放在上面的任意部分却不会提示出错....
我想问为什么?
---------------最后想问下,不放到protect和public声明的函数或过程与放在里面声明的有什么区别------------
求解迷惑............

解决方案 »

  1.   

    第三个问题,默认是放在published里面。
    前两个问题,搞不清楚。
    期待高手回答。
      

  2.   

    问题一:这里有答案:http://topic.csdn.net/t/20030527/09/1838571.html问题二:楼主是怎么测试的?我怎么没测试成功。
      

  3.   

    问题三:Type
      AClass = Class
       //此处默认是published
      public
       //公开的
      private
       //私有的
      protect
       //保护的
      published
       //发行的
    end;
      

  4.   

    其实我写错了代码还不算精确,最好将下面代码的f1改成f
    procedure TForm1.Amethod(f1:string); 
    begin 
    // 
    end; 
    还有就是请您再测试一遍,我是在一个运行没有错误的程序里添加一个Unit单元,然后把要测试的重载函数放在Unit单元并改动他们声明的位置.....经过测试程序没有爆错啊!
    请求解答这个问题........
      

  5.   

    第一个问题很明显啦,TForm的Default区域是Published,Published下不允许重载方法。第二个问题,普通类的Default区域不是Published,可以重载。第三个问题,不放在public这些下的东西,都是属于Default区域,至于Default区域相当于什么可见性,就要看类而定了。
      

  6.   

    例如说TObject的Default区域就相当于public,所以你这么写不会报错。
      

  7.   

    真的吗?
    对了我怎么在自己买的书本上看不到你写的这些,我看的书本上没有写default是属于什么可见度。听你这么说default区域还要针对什么类型才属于什么可见度。有的属于public,有的属于published等等,
    能不能告诉我哪本书将delphi剖析的比较清楚的
      

  8.   

    看帮助
    Only one member of a set of overloaded functions may be published because the RTTI generated for procedures only contains the name.In the example shown here, both overloaded p1 functions are contained in a published section, which is not allowed.Further, since the $M+ state is used, the Extended class starts with published visibility, thus the error will also appear for this class also.再看源代码:
    {$M+}  TPersistent = class(TObject)
      private
        procedure AssignError(Source: TPersistent);
      protected
        procedure AssignTo(Dest: TPersistent); virtual;
        procedure DefineProperties(Filer: TFiler); virtual;
        function  GetOwner: TPersistent; dynamic;
      public
        destructor Destroy; override;
        procedure Assign(Source: TPersistent); virtual;
        function  GetNamePath: string; dynamic;
      end;{$M-}
    所以从TPersistent开始,其子类都是默认为published可见。
    而published可见的方法需要在RTTI记录方法名,所以不支持重载,如果方法重载了,用方法名就无法定位到具体方法了。