DocCleanSuccess example for C++ Builder

procedure TForm1.Button3Click(Sender: TObject);
void __fastcall TForm1::Button3Click(TObject *Sender)
{
   int nRet;
    // This example updates a region with all 1x1 to 3x3 specks that are solid black
    // If a speck has any white pixels, it is NOT part of the updated region
    // The call is configured to update a single LEAD region with all changes
    // The image itself is unchanged
    // The DotRemove Event is used to display information about each speck that is removed

    nRet = LEADImage1->DotRemove (DOT_USE_SIZE | DOT_SINGLE_REGION | DOT_LEAD_REGION | DOT_IMAGE_UNCHANGED, 1, 1, 3, 3);
    if (nRet == SUCCESS) 
    {
        LEADImage1->FreeRgn ();
        LEADImage2->Bitmap = LEADImage1->DocCleanBitmap; // copy the result so we can get the rgn handle
        LEADImage1->SetRgnHandle (LEADImage2->GetRgnHandle (), 0, 0, L_RGN_SET);
        LEADImage2->Bitmap = 0; // no longer need copy
        LEADImage1->DocCleanBitmap = 0; // no longer need rgn either
        LEADImage1->RgnFrameType = ftAnimated;
    }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::LEADImage1DotRemove (TObject *Sender,
      L_HRGN hDotRgn, int nBoundingRectLeft, int nBoundingRectTop,
      int nBoundingRectWidth, int nBoundingRectHeight, int iWhiteCount,
      int iBlackCount)
{
    long int nRet ;
    char szTemp[256];

    wsprintf(szTemp,"Dot Found at %d,%d,%d,%d  WhiteCount=  %d  BlackCount= %d",
    nBoundingRectLeft,
    nBoundingRectTop,
    nBoundingRectWidth,
    nBoundingRectHeight,
    iWhiteCount,
    iBlackCount);

    OutputDebugString(szTemp);
    // Do not remove the speck if it contains any white pixels

    if (iWhiteCount > 0)
        nRet = SUCCESS_NOREMOVE;
    else
        nRet = SUCCESS_REMOVE;

    LEADImage1->DocCleanSuccess = nRet;
}