> Hi!
> I have an global object in UnitX, I create it while constructing another
> object, but when i reference it later from another type of object (from
> another unit), then this global object appears to be nil. (but when i create
> it in initialization section, all is OK).
> What I'm doing wrong?
> Aivar Annamaa
Using genralisations does not help solve specific problems. What kind of object
is the object in unitX? If you have to specify an owner, and you
specified self,
the object will be freed when the object in which it was created is destroyed.
The global object can only be nil if you have not created it or if
you set it to
nil yourself. (Global memory appears to start off initialised to zero
in Delphi,
I have not found anything in the help which says this should be so,
it is safest
to declare global objects like this: var myobject:Tmyobject=nil;)
Even after you free it, the value in the object's pointer is not
normally cleared,
so although you will get an access violation if you try yo use it, a comparison
with nil should fail.
--
Sincerely,
Andreas Kyriacou
----------------
http://www.andrikkos.co.uk (Imagine! Image Viewer)