Nope.

A constructor is a special class method. When Delphi calls a constructor, it
allocates a new block of memory and returns the pointer to that. On the
other hand, you can (I think) do this:
bitmap := TBitmap.Create; { Allocates memory and runs constructor }
bitmap.Create; { just runs the constructor, doesnt allocate memory }
BUT
The constructor of TBitmap allocates its own memory structures, and sets
internal pointer values. It assumes its being run just after the memory has
been allocated and cleared, so you'll have a lot of memory leaks anyway.

Think of it this way:

var
  bitmap : TBitmap { This is a pointer - eight bytes of memory. As I've put
it in a var statement, its on the stack. }
begin
  bitmap := TBitmap.Create;
{ bitmap is still a pointer, still the same size. However it now contains
the address of another structure on the heap, which is sizeof(TBitmap) bytes
in size. }
{ In addition, the structure itself contains pointers (8 bytes) to other
structures (such as TBitmapImage), which are also allocated on the heap (by
the constructor of TBitmap, and other places as needed). }
  bitmap := TBitmap.Create;
{ Now you've allocated a NEW set of memory on the heap, and lost the
references to the old ones. }

Regards,
  Andrew Cooke.

> -----Original Message-----
> From: Alistair George [SMTP:[EMAIL PROTECTED]]
> Sent: Friday, August 20, 1999 3:15 PM
> To:   Multiple recipients of list delphi
> Subject:      [DUG]:  Bitmaps again
> 
> Is there anything wrong with creating another instance of a bitmap even if
> its created?
> I get no error message if I do this.
> eg earlier call:
>     bitmap := Tbitmap.Create;
> secondary call
>     bitmap := Tbitmap.Create;
> without a free in between
> 
> Since bitmap is a pointer to the same memory location it should be ok
> right?
> Alistair Grant George
> mailto:[EMAIL PROTECTED]
> Products:
> http://v-share.com/~v_bigal/
> 
> 
> --------------------------------------------------------------------------
> -
>     New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
>                   Website: http://www.delphi.org.nz
---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz

Reply via email to