Where's My Canvas?

0

I broke some working code, but can't figure out how I could have caused this particular problem.

I have a TImage in a scrollbox.  If I build a bitmap from an array of data and Image1.picture.bitmap.assign(the_constructed_image), everything works as it has for quite a while.  But either AFTER I have successfully done that or on a FIRST CALL to the image/scrollbox-containing window, 

   Image1.picture.bitmap.assign(a_different_bitmap_image);  {a_different_bitmap_image is a tbitmap}

   Image1.width := image1.picture.bitmap.width; {debugger confirms the value is as expected}

   Image1.height := image1.picture.bitmap.height;  {debugger confirms value}

   Image1.picture.bitmap.pixelformat := pf32bit;  {same as the image that was just assigned}

  {use debugger and evaluate assigned(image1.canvas).  Result : true}

the very next instruction has an access violation ($C0000005).  And the command?

  Image1.canvas.pixels[0,0] := clblack;

How can an image and picture exist without a canvas?  Before doing the assignment, I used scanline to go through a_different_bitmap_image (a tbitmap) that was about to be copied to ensure that it was there and the size I expected -- it is.  Ever seen something like this?

  • Accepted Answer

    Tuesday, September 12 2017, 03:16 PM - #Permalink
    0

    Additional useful information: if instead of trying to display a_different_bitmap_image in the original timage I open a new screen and display it over there, the image displays just fine.  However, when I go to shut down the program, I get the same access violation error when the program is destroying images.  This may be a matter of ownership?

    The reply is currently minimized Show
  • Responses (2)
    • Accepted Answer

      Wednesday, September 13 2017, 10:41 AM - #Permalink
      0

      You are doing this(Image1.picture.bitmap.assign),  but accessing the Image1.Canvas: 

      Did you try this?

      Image1.picture.bitmap.canvas.pixels[0,0]:=clBlack;

       

      The reply is currently minimized Show
    • Accepted Answer

      Wednesday, September 13 2017, 08:47 AM - #Permalink
      0

      Turned out there was an object deleted under some circumstances, so OF COURSE the pointer was null!

      The reply is currently minimized Show
    Your Reply

    Please login to post a reply