差不多,只不过PUBLISHED属性就是出现在Object Inspector中的可视属性,
PUBLISHED是DELPHI特有的,VC中没有这个概念

解决方案 »

  1.   

    Public:   不能在属性编辑器看到;
    Published: 能在属性编辑器里看到;
    就这点区别.
      

  2.   


      Published是缺省的关键字!
      

  3.   

    publish是public的一个子集:所有的方法都可以 publish, 但是类不可以 publish多次,字段只有类class 接口interface,才可以被pulish。
      

  4.   

    public{公有变量声名}就是说在这里申明的变量在其他的单元可以调用.
    在published申明的变量的可见性和public的一样,都可以为其他的单元所使用
    但他们的区别在于published的运行期类型信息不同,一个published的变量不但
    可以在运行期间改变,而且可以直接在设计期间(Object Inspector)进行设计
    只要相应的方法,实际上published中的变量都是delphi工具的接口
      

  5.   

    Published的对象方法和属性可以生成RTTI信息。RTTI是很重要的,你经常使用的AS、IS就使用了RTTI信息。
      

  6.   

    需要特别注意的是published是delphi和bcb专有的
      

  7.   

    赞成ghz2000和C_Sharp观点,其实二者区别就是Published部分可以产生运行期类型信息(RTTI).
      

  8.   

    我声明了一个Published的变量和一个Published的过程在窗体类中,
    为什么在ObjectInspector中看不到呢?如果能看到,在哪里能看到?难道,还要声明成Property才可以吗?如果是这样,那么Published的变量和Procedure
    又有什么意义呢...问题也许很foolish,大家不要介意,当我是个傻菜鸟好了。
      

  9.   

    关于产生RTTI,能举个例子吗?我加分了...为了表示我的诚意!
      

  10.   

    以下是我做的试验。在Object Inspector中仍然是只能看到TButton1,看不到我声明的
    Procedure aaa() 和 Variant IntegerTest1。
    看来区别不是那么简单...~unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      StdCtrls;type
      TForm1 = class(TForm)
      published
        IntegerTest2: Integer;
        Button1: TButton;
        Procedure aaa();
      private
        { Private declarations }
      public
        IntegerTest1: Integer;
        Procedure bbb();
        { Public declarations }
      end;var
      Form1: TForm1;implementationProcedure TForm1.aaa();
    Begin
        showmessage('aaa');
    End;Procedure TForm1.bbb();
    Begin
        showmessage('bbb');
    End;{$R *.DFM}end.
      

  11.   

    以上程序编译不过。提示 "IntegerTest2 Not a class type or interface type"
    是不是published中不能声明普通变量,只能声明类的对象?
    但Procedure却又可以放在Published中又试着将Button1:TButton放到Public中,执行出错。"Class TButton not found"
    改回到Published,可以。
    ???是不是可视化组件只能声明为Published?
      

  12.   

        Published members have the same visibility as public members. The difference is that runtime type information (RTTI) is generated for published members. RTTI allows an application to query the fields and properties of an object dynamically and to locate its methods. Delphi uses RTTI to access the values of properties when saving and loading form (.DFM) files, to display properties in the Object Inspector, and to associate specific methods (called event handlers) with specific properties (called events).    Published properties are restricted to certain data types. Ordinal, string, class, interface, and method-pointer types can be published. So can set types, provided the upper and lower bounds of the base type have ordinal values between 0 and 31. (In other words, the set must fit in a byte, word, or double word.) Any real type except Real48 can be published. Array properties cannot be published.    All methods are publishable, but a class cannot publish two or more overloaded methods with the same name. Fields can be published only if they are of a class or interface type.    A class cannot have published members unless it is compiled in the {$M+} state or descends from a class compiled in the {$M+} state. Most classes with published members derive from TPersistent, which is compiled in the {$M+} state, so it is seldom necessary to use the $M directive.
      

  13.   

    其实published一般用于创建新的组件;
    并且注意有关键字:property IntegerTest2: Integer;
    如果想在Object Inspector看到你的 integerTest2
    你还要写相应的write ,read方法;  private
       { Private declarations }
      fIntegerTest2 : integer;
      function GetIntegerTest2:integer;
      procedure SetIntegerTest2(Value:integer);
      
      public
        procedure aaa();
        procedure bbb();
        IntegerTest1: Integer;
        { Public declarations }
      published
        IntegerTest2: Integer;
      read GetIntegerTest2
      write SetIntegerTest2;
      end;
      

  14.   

    published生成RTTI信息是对的,但不是绝对,RTTI不只是published. 比如TypeInfo函数就不只是针对published的。而as, is是针对类引用的,跟published扯不上。一个没有published部分的类,也可能用as, is操作符。
    public不能用名字来引用,而published可以。如你可以用methodAddress以名字得到一个published的方法的地址而进行调用。
    总的说来,最明显的差别是:published的东东可以在Object Inspector中看见,能保存到流中及DFM文件中,而public只是运行时的。published的变量和方法虽然在Object Inspector中看不到,但一样可以用名字来引用。