Board index » delphi » Assignment of Objects

Assignment of Objects

When one object is assigned to another do they both point to the same
physical location in memeory??

eg:
----
var
  MyList : TStringList;
  MyObj,
  MyOtherObj : TMyObject
begin

MyList := TStringList.Create;
MyObj := TMyObject.Create;

MyList.AddObject('hello',TObject(MyObj));

MyOtherObj := MyList.Objects[0];

-----

Do MyList.Objects[0] and MyOtherObj both point to the same place in memory
 1 instance of the class TMyObject??)

Thanks

Si.

 

Re:Assignment of Objects


Yes, both things are pointers to the same address in memory. It's also
important to understand that freeing the TStringList does *not* free the
objects it contains.

HTH, Glynn

Quote
Simon Gibbs wrote:

> When one object is assigned to another do they both point to the same
> physical location in memeory??

> eg:
> ----
> var
>   MyList : TStringList;
>   MyObj,
>   MyOtherObj : TMyObject
> begin

> MyList := TStringList.Create;
> MyObj := TMyObject.Create;

> MyList.AddObject('hello',TObject(MyObj));

> MyOtherObj := MyList.Objects[0];

> -----

> Do MyList.Objects[0] and MyOtherObj both point to the same place in memory
>  1 instance of the class TMyObject??)

> Thanks

> Si.

Other Threads