You need to call free as the help says but in this example bitmap and oldBM 
are the same as you assigning bitmap from oldBM.  You then free bitmap, 
which is now oldbm and return the free'd oldbm via bitmap.  You are also 
left with a dangling bitmap that you origianly assigned to bitmap!

Get it?


>From: "Alistair George" <[EMAIL PROTECTED]>
>Reply-To: [EMAIL PROTECTED]
>To: Multiple recipients of list delphi <[EMAIL PROTECTED]>
>Subject: [DUG]:  Any comments
>Date: Wed, 28 Jul 1999 07:10:47 +1200
>
>Morning all.
>Yesterday day I spent a couple more wasted hours sorting out a problemo in
>my software which I eventually chased up to the function call not returning
>a bitmap:
>
>function myapp.getaBM(oldBM:tbitmap):tbitmap;
>var bitmap:tbitmap
>begin
>bitmap:=tbitmap.create;
>//rest bitmap initialize here
>bitmap:=oldBM;
>result:=bitmap;
>bitmap.free;    //gwan get lost result
>end;
>
>Now to me, the following quote from help seems to indicate the above code
>would be right:
>Any object instantiated by a call to Create should be destroyed by a call 
>to
>Free, so that the object an be properly destroyed and the memory released.
>Free is successful even if the object is nil, so if the object was never
>initialized, for example, calling Free wont result in an error.
>
>And the variable RESULT is always available for use. Seems RESULT is
>destroyed with the free, because the only way the code works is by using
>FreeOnRelease instead, which the bible does not recommend.
>
>OR do I leave it up to the procedure/function to destroy all the items
>created within that area on exit, just like any other variable, thus
>alleviating the use of Free?
>Re the above I often see Try...except free xxxx  in called functions or
>procedures, written by others, who are much more adept than me.
>Cheers,
>Al+
>
>---------------------------------------------------------------------------
>     New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
>                   Website: http://www.delphi.org.nz


______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com
---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz

Reply via email to