{*******************************************************}
{ }
{ 继承范例 }
{ }
{ }
{ 版权所有 (C) 2000,2001 真光软件 }
{*******************************************************}
unit clsPerson;
{*******************************************************
项目:
模块:TPerson,TTeacher,TStudent
描述:OOP范例类
版本:1.0
日期:2001.9.23
作者:黄洪烈
更新:2001.9.23
TODO:
*******************************************************}
interface
uses
clsApplication,Forms,classes,Dialogs;
const
C_tblStudent=''student.db'';//学生类表名
C_tblTeacher=''teacher.db'';//老师类表名
type
TPerson=class(TDbRecordset)
private
FTelephone: string;
FId: string;
FName: string;
function GetId: string;
function GetName: string;
function GetTelephone: string;
protected
procedure BindFieldValues;virtual;//设置字段值
public
property Id:string read GetId write FId;
property Name:string read GetName write FName;
property Telephone:string read GetTelephone write FTelephone;
procedure ShowId;//显示编码
end;
TStudent=class(TPerson)
private
FTotalScore: integer;
function GetTotalScore: integer;
protected
procedure BindFieldValues;override;//设置字段值
public
constructor Create(AOwner:TComponent);override;
function Post:boolean;override;
property TotalScore:integer read GetTotalScore write FTotalScore;
end;
TTeacher=class(TPerson)
private
FSubject: string;
function GetSubject: string;
protected
procedure BindFieldValues;override;//设置字段值
public
constructor Create(AOwner:TComponent);override;
function Post:boolean;override;
property Subject:string read GetSubject write FSubject;
end;
implementation
{ TPerson }
{设置字段值}
procedure TPerson.BindFieldValues;
begin
FTable.Edit;
FTable.FieldByName(''Id'').AsString:=FId;
FTable.FieldByName(''Name'').AsString:=FName;
FTable.FieldByName(''Telephone'').AsString:=FTelephone;
end;
{定义字段属性}
function TPerson.GetId: string;
begin
FId:=FTable.FieldByName(''Id'').AsString;
Result:=FId;
end;
function TPerson.GetName: string;
begin
FName:=FTable.FieldByName(''Name'').AsString;
Result:=FName;
end;
function TPerson.GetTelephone: string;
begin
FTelephone:=FTable.Fiel