MM生成的一个类,

原贴见:http://community.csdn.net/Expert/topic/3793/3793756.xml
这里的是他的MM图,有MM的可以导进去看看。



代码 pro3.pas
unit pro3;

interface

uses
 SysUtils,Dialogs,Contnrs;

type
  TProduct = class(TObject)
  private
    FName: string;
    FPrice: Double;
    function GetName: string;
    function GetPrice: Double;
    procedure SetName(const Value: string);
    procedure SetPrice(Value: Double);
  public
    constructor Create; overload;
    procedure SayHello; virtual;
    property Name: string read GetName write SetName;
    property Price: Double read GetPrice write SetPrice;
  end;
 
  TProductXY = class(TProduct)
  public
    procedure SayHello; overload;
  end;
 
  TProductZY = class(TProduct)
  public
    procedure SayHello; overload;
  end;
 
  TStore = class(TObject)
  private
    FProductList: TObjectList;
    function GetProductList: TObjectList;
  public
    constructor Create;
    destructor Destroy; override;
    procedure AddProduct(aProduct:TProduct);
    property ProductList: TObjectList read GetProductList;
  end;
 

implementation

{
*********************************** TProduct ***********************************
}
constructor TProduct.Create;
begin
   FName:='商品TProduct';
  FPrice:=0;
  ShowMessage('商品被创建');
end;

function TProduct.GetName: string;
begin
  Result:=FName;
end;

function TProduct.GetPrice: Double;
begin
  Result:=FPrice;
end;

procedure TProduct.SayHello;
begin
end;

procedure TProduct.SetName(const Value: string);
begin
  if FName<>Value then
     FName:=Value
  else
     ;
end;

procedure TProduct.SetPrice(Value: Double);
begin
  If Value>0 then
     FPrice:=Value
  else
     FPrice:=0;
end;

{
********************************** TProductXY **********************************
}
procedure TProductXY.SayHello;
begin
  ShowMessage('我是西药,我的名字是'+Name+'单价:'+FloattoStr(Price));
end;

{
********************************** TProductZY **********************************
}
procedure TProductZY.SayHello;
begin
  ShowMessage('我是中药,我的名字是'+Name+'单价:'+FloattoStr(Price));
end;

{
************************************ TStore ************************************
}
constructor TStore.Create;
begin
  FProductList:=TObjectList.Create();
  FProductList.OwnsObjects := True;  //使FProductList在销毁时自动销毁其下拥有的对象
end;

destructor TStore.Destroy;
begin
  FProductList.Free;
  inherited Destroy;
end;

procedure TStore.AddProduct(aProduct:TProduct);
begin
  FProductList.Add(aProduct);
  ShowMessage(aProduct.Name+'被加入');
end;

function TStore.GetProductList: TObjectList;
begin
  Result:=FProductList;
end;


end.

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值