类的创建,是不是也在单元中,能不能给个小例子,做个类:myshow.具有属性:showinfo(显示的内容)和方法 showit。(myshow.showit('*****'),或者myshow.showit(showinfo))

解决方案 »

  1.   

    unit Unit1;interface
    type
      myshow = class(TObject)
      private
        shoinfo:string;
      public
        procedure showit;
      end;implementation
    procedure myshow.showit;
    begin
      showmessage(showinfo);
    end;end.
      

  2.   

    unit Unit1;interface
    type
      myshow = class(TObject)
      private
        s:string;
      property
        showinfo :string read s write SetS;
        procedure SetS(const Value: string);
      public
        procedure showit;
      end;implementation
    procedure myshow.SetS(const Value: string);
    begin
      showinfo:=s;
    end;procedure myshow.showit;
    begin
      showmessage(showinfo);
    end;end.
      

  3.   

    //unit Unit2;
    interfaceuses
      Dialogs;type
      myshow = class(TObject)
      private
        Fs:string;
        procedure SetFs(const Value: string);
      protected
        property showinfo :string read Fs write SetFs;
      public
        procedure showit;
      end;implementation{ myshow }procedure myshow.SetFs(const Value: string);
    begin
      Fs := Value;
    end;
    procedure myshow.showit;
    begin
      showmessage(showinfo);
    end;end.