Salut Bryan Smith !
Dans un message de Bryan Smith dat‚ du 01 May 97 10:52:28 il ‚tait dit:
BS> the program GPF'ed whenever it exited.
BS> BodyFont := FontDialog1.Font ;
BS> ... Text deleted ....
BS> BodyFont.Assign(FontDialog.Font) ;
BS> Happily, this fixed the problem.
BS> Can anybody provide some insight into what is going on here ?
Assigning one object variable to another object variable makes the two
variable reference the same object in m‚mory. Remember that when you
create an object, Delphi allocate memory to hold the object, then call the
constructor to initialize it and then return the memory address where
the object is stored. This memory addresse is stored in the object
variable:
MyObject := TSomeObjectType.Create(Self);
OtherObject := MyObject;
MyObject will contain the address where the object is stored. This is
a reference to the object. OtherObject is assigned the value of
MyObject. That is: OtherObject now reference the same object in
memory: you have two variables refering to the same and only one
object in memory. Only one destroy method call is required and
allowed.
On the other side, the Assign method copy the data from one object to
another object, making a data duplicate:
MyObject1 := TSomeObjectType.Create(Self);
MyObject2 := TSomeObjectType.Create(Self);
MyObject2.Assign(MyObject1);
Here two object are created an initialized. The the second object is
assigned the value of the first. That means that the two object will
have the same value for their properties, but are in different memory
addresses. Two destroy method are required: one for each object.
Amiti‚s,
{-Francois Piette-}
francois.piette@ping.be
http://www.rtfm.be/fpiette
--- SvFido 1.32
---------------
* Origin: OverByte BBS (Embourg-Belgium) 32-4-3651395 VFC/V34+ (2:293/2202)
|