如果在每个类里面都加入这个方法太累赘了,请问有其他方法吗?

解决方案 »

  1.   

    类方法class function Ttype.ssssxxxsx:xxxx
    调用  Ttype.ssssxxxxxssx
      

  2.   

    public class a
    {
      public void test()
    }public class b extends a
    {
      public void testb()
    }public class c extends a
    {
       public void testc()}
      

  3.   

    写个基类不就行了,基类里写函数TBaseClassTClassA = class(TBaseClass)
      

  4.   

    放两个button在form上。代码如下。unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      StdCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        Button2: TButton;
        procedure Button1Click(Sender: TObject);
        procedure FormCreate(Sender: TObject);
        procedure Button2Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }  end;  x=class
        public
          procedure test;
      end;  y=class(x)
        end;
      z=class(x)
        end;var
      Form1: TForm1;
      testy:y;
      testz:z;implementation{$R *.DFM}{ x }procedure x.test;
    begin
      showmessage('x');
    end;procedure TForm1.FormCreate(Sender: TObject);
    begin
     testy:=y.Create;
     testz:=z.Create;
    end;procedure TForm1.Button2Click(Sender: TObject);
    begin
     testz.test;
    end;procedure TForm1.Button1Click(Sender: TObject);
    begin
     testy.test;
    end;
    end.
      

  5.   

    Class HelpersTMyClassHelper = class helper for TMyClass
    除了析构解析函数。Class procedure 好像也不可以。
    其他的函数,如果重名,则用 helper 里的替代。
    否则就可以作为补充(只要你 uses 这个单元)。
    就会出现 Button1.About 这种原本没有的函数了。type
      TMyClass = class    procedure MyProc;
    function  MyFunc: Integer;
      end;   ...   procedure TMyClass.MyProc;
       var
     X: Integer;
       begin
      X := MyFunc;
       end;   function TMyClass.MyFunc: Integer;
       begin
       ...
       end;...type
       TMyClassHelper = class helper for TMyClass
     procedure HelloWorld;
     function MyFunc: Integer;
       end;   ...   procedure TMyClassHelper.HelloWorld;
       begin
     WriteLn(Self.ClassName); // Self refers to TMyClass type, not TMyClassHelper   end;   function TMyClassHelper.MyFunc: Integer;
       begin
     ...
       end;
    ...var
      X: TMyClass;
    begin
      X := TMyClass.Create;
      X.MyProc;    // Calls TMyClass.MyProc
      X.HelloWorld; // Calls TMyClassHelper.HelloWorld
      X.MyFunc; // Calls TMyClassHelper.MyFuncend;