out of memory错误

zhongjinting 2009-04-12 10:08:02
TPerson、ICustomer分别是对人和公司的封装,TPersonalCustomer从它俩继承,封装个人类型的客户(对应的还有公司类型的客户),TPersonalCustomer重载了TPerson类中的Name属性,但是在给Name赋值的时候,却引发了Out of Memory错误,为什么呢?

代码片段:

//// Classes and Interface
type
TPerson = class;
TPersonalCustomer = class;
ICustomer = interface
function GetDisplayName: WideString; stdcall;
property DisplayName: WideString read GetDisplayName;
end;

TPerson = class(TInterfacedObject, IInterface)
private
FName: WideString;
procedure SetName(const Value: WideString);
published
property Name: WideString read FName write SetName;
end;

TPersonalCustomer = class(TPerson, ICustomer)
private
FNoshow: Boolean;
public
function GetDisplayName: WideString; stdcall;
published
property Name;
end;

implementation

uses SysUtils,
Dialogs;

procedure TPerson.SetName(const Value: WideString);
begin
//ShowMessage(Value);
FName := Value; <-- out of memory here
end;

function TPersonalCustomer.GetDisplayName: WideString;
begin
Result :='客户'+ Name;
end;

end.


////// codes in the form

procedure TForm1.btn1Click(Sender: TObject);
var
Customer : ICustomer;
begin
Customer := TPersonalCustomer.Create;
TPerson(Customer).Name := widestring(edt1.Text );
ShowMessage(Customer.DisplayName);
Customer := nil;
end;

...全文
53 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhongjinting 2009-04-12
  • 打赏
  • 举报
回复
谢谢
sanguomi 2009-04-12
  • 打赏
  • 举报
回复
var
Customer: ICustomer;
定义对象错拉

16,748

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 语言基础/算法/系统设计
社区管理员
  • 语言基础/算法/系统设计社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧