首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

有关类的定义,该如何解决

2012-02-04 
有关类的定义有两个窗体:Form1Form2在form1中定义一个类例如:TypeTuserclasspulbicfunctionGetMyPassword

有关类的定义
有两个窗体:   Form1     Form2
在form1中定义一个类例如:
Type
    Tuser=class
          pulbic  
              function   GetMyPassword():string;
end;

如果我想在form2中的定义窗体级变量的地方定义一个Tuser类的继承类.如何来定义呢.
unit   Unit2;
interface
uses
    Windows,   Messages,   SysUtils,   Variants,   Classes,   Graphics,   Controls,   Forms,
    Dialogs,   StdCtrls,   ExtCtrls,DateUtils;
type
    TForm1   =   class(TForm)
        Button1:   TButton;
        procedure   Timer1Timer(Sender:   TObject);
        procedure   Button1Click(Sender:   TObject);
            private
        {   Private   declarations   }
    public
        {   Public   declarations   }
    end;

var
    Form1:   TForm1;
---------------> 在这个地方定义一个TYongHu,TYongHu是类Tuser的继承.并且不再为TYonghu添加新的方法.
implementation

uses   Unit1;

{$R   *.dfm}

[解决办法]
为什么要这样定义啊?
[解决办法]
如果我想在form2中的定义窗体级变量的地方定义一个Tuser类的继承类.如何来定义呢.
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls,DateUtils, Unit1;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Timer1Timer(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
Fuser:Tuser;
public
{ Public declarations }
end;

var
Form1: TForm1;
---------------> 在这个地方定义一个TYongHu,TYongHu是类Tuser的继承.并且不再为TYonghu添加新的方法.
implementation


{$R *.dfm}

[解决办法]
implementation

uses Unit1;

type
TYongHu= class(Tuser)
end;

//试了一下,还真可以在implementation定义类,呵呵

热点排行