When you set Action to caFree, that causes the form to be freed.
From Embarcadero's Help: caFree -- The form is closed and all allocated memory for the form is freed.
My actual code is a lot more complicated then the code I originally posted:
procedure TOverlayImageSourceFrame.ImageWindowClose (Sender: TObject;
var Action: TCloseAction);
begin
if (Assigned(FImageWindow)) And (Sender = FImageWindow) then
begin
FImageWindow.ImgEdit.SetExternalBitmap(nil);
if TIEBitmap_(FFrameImage).fOwner = FImageWindow.ImgEdit then
TIEBitmap_(FFrameImage).fOwner := Nil;
if TIEBitmap_(FOverlayImage).fOwner = FImageWindow.ImgEdit then
TIEBitmap_(FOverlayImage).fOwner := Nil;
if TIEBitmap_(FRenderImage).fOwner = FImageWindow.ImgEdit then
TIEBitmap_(FRenderImage).fOwner := Nil;
FImageWindow := nil;
Action := caFree;
end
else if (Assigned(FRenderWindow)) And (Sender = FRenderWindow) then
begin
FRenderWindow.ImgEdit.SetExternalBitmap(nil);
if TIEBitmap_(FRenderImage).fOwner = FRenderWindow.ImgEdit then
TIEBitmap_(FRenderImage).fOwner := Nil;
FRenderWindow := nil;
Action := caFree;
end;
end;
When I run my app I hit everyone of the IF cases depending on the window that is closed and the image that is displayed in it.
The issue is in procedure TImageEnView.SetExternalBitmap(bmp: TIEBitmap). When bmp is Nil, your code reaches this section of the procedure:
else
begin
TIEImageLayer_( CurrentLayer as TIEImageLayer ).fFreeBitmapOnDestroy := true;
fIEBitmap := TIEBitmap.Create;
TIEBitmap_(fIEBitmap).fOwner := Self;
{$IFDEF IELegacyBitmapSupport}
fBitmap := nil;
{$ENDIF}
// Assign new fIEBitmap to current layer
SyncBitmapToCurrentLayer();
end;
Notice that you always set fOwner to Self. You shouldn't do that when bmp is Nil, instead fOwner should be set to Nil to unlink the TImageEnView.
Tim F