对TList增加一些方法后的问题:(60分)

  • 主题发起人 主题发起人 noall
  • 开始时间 开始时间
N

noall

Unregistered / Unconfirmed
GUEST, unregistred user!
先定义:
type
TBaseObject = class(Tobject)
private
FX: Integer;
FY: Integer;
{....}
public
Constructor Create;
destructor Destroy;
override;
property X: Integer read FX write FX;
property Y: Integer read FY write FY;
{....}
end;
type
Tcxbase = class(TList)
private
FTest: Integer;
public
Procedure addObject(NewObject: TBaseObject);
property Test: Integer read FTest write FTest default 0;
end;

在实现中:
constructor TBaseObject.Create;
begin
inherited Create;
Fx:=0;
Fy:=0;
end;

destructor TBaseObject.Destroy;
begin
inherited Destroy;
end;

procedure Tcxbase.addObject(NewObject: TBaseObject);
begin
Add(NewObject);
end;
现在在Click中:
procedure TForm1.Button1Click(Sender: TObject);
Var ph:Tcxbase;
newobject:TBaseObject;
begin
newobject:=TBaseObject.Create;
newobject.X :=1;
newobject.y:=2;
ph.addObject(newobject);//执行到这里时发生了错误,请问是什么原因呢?谢谢
end;
 
废话!ph还没有create哪!
 
哦,谢谢!行了,
那现在我要取出刚才所加入的值,应该如何做呢?
如将刚才所加的newobject中的X,y如何从PH中取出,应在哪增加些什么?
 
TBaseObject(ph.Items).x
 
刚才用
var ExObject:TBaseObject
ExObject:=ph.items as TBaseObject 不行。
再请问一下,那在PH.free前,是否要将每个的ph.items释放呢?
 
当然要释放了
 
多人接受答案了。
 
后退
顶部