读书人

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

发布时间: 2012-02-04 15:43:09 作者: rapoo

有关类的定义
有两个窗体: 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定义类,呵呵

读书人网 >.NET

热点推荐