大家好,我一个DELPHI的爱好者,同时我也是一名在校的学生.但我对类的理解不是很明白,所以求大家帮助,在DELPHI里如何定义一个类,并且如何在其它的窗体中调用这个类.
      谢谢.           

解决方案 »

  1.   

    比如:
    type
      TForm1 = class(TForm)
        Edit1: TEdit;
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
        procedure Edit1KeyPress(Sender: TObject; var Key: Char);
      private
        { Private declarations }
      public
        { Public declarations }
      end;就已经定义了一个TForm1的类,如果是你自己定义的类,只要新建一个Unit,按照以上语法定义就可以了,如果其他单元要引用的话只要use你定义类的单元即可!
      

  2.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, DB, ADODB;type
      TForm1 = class(TForm)
        ADOStoredProc1: TADOStoredProc;
        procedure FormCreate(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;  TFake = class
      public
        procedure ShowInfo;
      end;var
      Form1: TForm1;implementation{$R *.dfm}
    procedure TFake.ShowInfo;
    begin
      ShowMessage('不要“跪求”,没有尊严');
    end;
    unit Unit2;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs;type
      TForm2 = class(TForm)
        procedure FormCreate(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form2: TForm2;implementationuses Unit1;{$R *.dfm}procedure TForm2.FormCreate(Sender: TObject);
    var
      F: TFake;
    begin
      F := TFake.Create;
      F.ShowInfo;
      F.Free;
    end;end.————————————————————————————————————
    宠辱不惊,看庭前花开花落,去留无意;毁誉由人,望天上云卷云舒,聚散任风。
    ————————————————————————————————————
      

  3.   

    不过还是建议你多看看书,你在校的话就更方便了,到图书馆随便借一本Delphi方面的书就有讲解的!
      

  4.   

    比如上面那位老大的《Delphi精要》就成了,呵呵!
    建议你买来看看,很不错的!
      

  5.   

    你要看一些面向对象的书了。《delphi高手突破》可以看看。比如创建一个TMan类
    TMan = class
    private
      FName : string;
    public
      constructor Create(name : string);
      procedure sayHello();
    end;implementationconstructor TMan.Create(name : string);
    begin
      FName:=name;
    end;procedure TMan.sayHello();
    begin
      showmessage('hello');
    end;
    在单元中就可以创建该类的对象。
    var I : TManI:=TMan.Create('Jack');
    I.sayHello;