GetRgnHandle example for Delphi

The following code creates a region, saves its handle and adds the saved region beside the current region.

var
   sRet: Smallint;
   SavedRegion: Longint;
   OffsetX, OffsetY: Single;
   RasterProc: LEADRasterProcess;
begin
   RasterProc:= CreateComObject (CLASS_LEADRasterProcess ) as LEADRasterProcess;
   
   //Initialize the variables that we will manipulate to simulate mouse coordinates.
   OffsetX:= LEADRasterView1.Raster.BitmapWidth / 8;
   OffsetY:= LEADRasterView1.Raster.BitmapHeight / 6;
   //Create an elliptical region.
   LEADRasterView1.Raster.SetRgnEllipse (OffsetX, OffsetY, OffsetX, OffsetY, L_RGN_SET);
   //Save a copy of the region.
   SavedRegion:= LEADRasterView1.Raster.GetRgnHandle;
   //Add the saved region to the bitmap, offsetting it so that we can see it.
   LEADRasterView1.Raster.SetRgnHandle (SavedRegion, OffsetX, OffsetY, L_RGN_OR);
   //Delete the saved region.
   LEADRasterView1.Raster.DeleteRgnHandle (SavedRegion);
   //Fill the bitmap region with blue.
   RasterProc.Fill (LEADRasterView1.Raster, RGB(0, 0, 255));
   //Free the bitmap region.
   LEADRasterView1.Raster.FreeRgn ();
   //Repaint the image so that we can see how the image was updated.
   LEADRasterView1.ForceRepaint (sRet);
end;